DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Note about "Learn You Some Erlang for Great Good"


Chapter 8

In road.erl, to demonstrate the process of folding on path tuple, you can add the following sentence after the line OptB2=... in method "shortest_step":

io:format("OptA1=~p, OptA2=~p, OptB1=~p, OptB2=~p~n", [OptA1, OptA2, OptB1, OptB2]),

The last sentence of road.erl in main method could also be erlang:halt()., while in book it's erlang:halt(0).. Both work ok.

chapter 13

  • In event.erl and evserv.erl, you can add the following line before every Pid ! Message to trace message flows between processes:

    io:format("~p send msg ~p to ~p~n", [self(), Message, Pid]),

  • In sup.erl, if you modify {'EXIT', _From, shutdown} -> to {'EXIT', _From, shutup} -> in loop/1, you will have to use "exit(SupPid, shutup)." instead of "exit(SupPid, shutdown)." to shutdown the sup process. See process_flag/2 and exit/2 for explanations;

Chapter 14

  • In kitty_server.erl, return_cat/2 put a cat in the shop (actually the list Cats, the parameter of loop/1). While order_cat/4 do 2 things: if shop is empty, create and return a new cat (then you can use return_cat to add this cat to shop), otherwise return the head of Cats. You can use folloing codes to verify(tom and bob are both set free):

    Pid = kitty_server:start_link(). C1 = kitty_server:order_cat(Pid, tom, yellow, "shinny"). rr(kitty_server). C2 = #cat{name=bob}. kitty_server:return_cat(Pid, C1). kitty_server:return_cat(Pid, C2). kitty_server:close_shop(Pid).

  • monitor technique in above kitty_server.erl: When Ref = erlang:monitor(process, Pid)., the calling process is "monitoring" Pid, which means 2 things:

    1. when Pid is down, the calling process will receive a 'DOWN' message;

    2. if the monitored target is a naming process, adding the Ref in message can guarantee correctness after target restarted (see "Naming Process" of chapter 12 for details);

  • You can use i(). or etop:start(). in erlang shell to list all processes; use process_info(Pid) to print detailed information about the Pid; use regs(). to list all registered processes;

Chapter 15

Use trade_calls:main_ab(). to demonstrate the use of trade_fsm;

Chapter 16

"curling_scoreboard" is a callback module (a handler in gen_event context). The return value of its init/1 function is {ok, State} (see erlang doc: gen_event: Module:init/1). So curling_scoreboard store the PID of client in its internal State variable (from ToPid in curling:join_feed/2, which called by curling:join_feed(Pid, self()).). At curling:add_points(Pid, "T1", 2)., both registered handlers receive message {add_points, Team, N}). Handler curling_scoreboard prints two message to show points are added. While handler curling_feed send a message it received to client process (the Pid in its handle_event/2 function, see erlang doc gen_event:Module:handle_event/2 for API specification);

Chapter 21

On p341, when set target directory as "~/docs/erlang/ppool-1.0" there is a exception. But when set it as "~/docs/erlang" everything goes fine:

$ ./erts-5.9.1/bin/erl -boot releases/1.0.0/start -erlcount directory '"/home/lichao/docs/erlang/"' -noshell

systools is simple than Reltool, which is much powerful than systools. Rebar can do release job, too. See Erlang rebar tutorial: generating releases and upgrades by Richard Jones;

Chapter 22

On p361, you have to modify the value of "lib_dirs" in file processquest-1.0.0.config at the root directory of processquest to the path where your "apps" directory resides, in my computer it's "/home/lichao/docs/erlang/processquest/apps" because I copy processquest to /home/lichao/docs/erlang. Then you can execute "{ok, Conf} = ... reltool:eval_target_spec...", and a bunch of files will be created under the "rel" directory under processquest.



Published

May 31, 2013

Last Updated

May 31, 2013

Category

Tech

Tags

  • erlang 15
  • fold 2

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor