|
71 | 71 | ``` |
72 | 72 |
|
73 | 73 | As shown, the function `say_something` writes its first argument the number of |
74 | | -times specified by second argument. The function `start` starts two Erlang |
| 74 | +times specified by the second argument. The function `start` starts two Erlang |
75 | 75 | processes, one that writes "hello" three times and one that writes "goodbye" |
76 | 76 | three times. Both processes use the function `say_something`. Notice that a |
77 | 77 | function used in this way by `spawn`, to start a process, must be exported from |
@@ -149,7 +149,7 @@ start() -> |
149 | 149 | ```erlang |
150 | 150 | 1> c(tut15). |
151 | 151 | {ok,tut15} |
152 | | -2> tut15: start(). |
| 152 | +2> tut15:start(). |
153 | 153 | <0.36.0> |
154 | 154 | Pong received ping |
155 | 155 | Ping received pong |
@@ -205,7 +205,7 @@ receive |
205 | 205 | pattern2 -> |
206 | 206 | actions2; |
207 | 207 | .... |
208 | | - patternN |
| 208 | + patternN -> |
209 | 209 | actionsN |
210 | 210 | end. |
211 | 211 | ``` |
@@ -254,7 +254,7 @@ process "ping": |
254 | 254 | Ping_PID ! pong |
255 | 255 | ``` |
256 | 256 |
|
257 | | -Notice how the operator "\!" is used to send messages. The syntax of "\!" is: |
| 257 | +Notice how the operator `!` is used to send messages. The syntax of `!` is: |
258 | 258 |
|
259 | 259 | ```erlang |
260 | 260 | Pid ! Message |
@@ -283,7 +283,7 @@ Pong_PID ! {ping, self()}, |
283 | 283 | ``` |
284 | 284 |
|
285 | 285 | `self/0` returns the pid of the process that executes `self/0`, in this case the |
286 | | -pid of "ping". (Recall the code for "pong", this lands up in the variable |
| 286 | +pid of "ping". (Recall the code for "pong", this ends up in the variable |
287 | 287 | `Ping_PID` in the `receive` previously explained.) |
288 | 288 |
|
289 | 289 | "Ping" now waits for a reply from "pong": |
@@ -397,7 +397,7 @@ pong ! {ping, self()}, |
397 | 397 | ## Distributed Programming |
398 | 398 |
|
399 | 399 | Let us rewrite the ping pong program with "ping" and "pong" on different |
400 | | -computers. First a few things are needed to set up to get this to work. The |
| 400 | +computers. First a few things need to be set up to get this to work. The |
401 | 401 | distributed Erlang implementation provides a very basic authentication mechanism |
402 | 402 | to prevent unintentional access to an Erlang system on another computer. Erlang |
403 | 403 | systems which talk to each other must have the same _magic cookie_. The easiest |
@@ -438,7 +438,7 @@ Erlang system running on a computer is called an _Erlang node_. |
438 | 438 |
|
439 | 439 | (Note: `erl -sname` assumes that all nodes are in the same IP domain and we can |
440 | 440 | use only the first component of the IP address, if we want to use nodes in |
441 | | -different domains we use `-name` instead, but then all IP address must be given |
| 441 | +different domains we use `-name` instead, but then all IP addresses must be given |
442 | 442 | in full.) |
443 | 443 |
|
444 | 444 | Here is the ping pong example modified to run on two separate nodes: |
@@ -533,7 +533,7 @@ Pong finished |
533 | 533 |
|
534 | 534 | Looking at the `tut17` code, you see that the `pong` function itself is |
535 | 535 | unchanged, the following lines work in the same way irrespective of on which |
536 | | -node the "ping" process is executes: |
| 536 | +node the "ping" process is executed: |
537 | 537 |
|
538 | 538 | ```erlang |
539 | 539 | {ping, Ping_PID} -> |
@@ -623,7 +623,7 @@ Before starting, notice the following: |
623 | 623 | - This example only shows the message passing logic - no attempt has been made |
624 | 624 | to provide a nice graphical user interface, although this can also be done in |
625 | 625 | Erlang. |
626 | | -- This sort of problem can be solved easier by use of the facilities in OTP, |
| 626 | +- This sort of problem can be solved more easily by using the facilities in OTP, |
627 | 627 | which also provide methods for updating code on the fly and so on (see |
628 | 628 | [OTP Design Principles](`e:system:design_principles.md`)). |
629 | 629 | - The first program contains some inadequacies regarding handling of nodes which |
@@ -666,9 +666,6 @@ File `messenger.erl`: |
666 | 666 | %%% Reply {messenger, logged_on} logon was successful |
667 | 667 | %%% |
668 | 668 | %%% To server: {ClientPid, logoff} |
669 | | -%%% Reply: {messenger, logged_off} |
670 | | -%%% |
671 | | -%%% To server: {ClientPid, logoff} |
672 | 669 | %%% Reply: no reply |
673 | 670 | %%% |
674 | 671 | %%% To server: {ClientPid, message_to, ToName, Message} send a message |
@@ -697,7 +694,7 @@ server_node() -> |
697 | 694 | messenger@super. |
698 | 695 |
|
699 | 696 | %%% This is the server process for the "messenger" |
700 | | -%%% the user list has the format [{ClientPid1, Name1},{ClientPid22, Name2},...] |
| 697 | +%%% the user list has the format [{ClientPid1, Name1},{ClientPid2, Name2},...] |
701 | 698 | server(User_List) -> |
702 | 699 | receive |
703 | 700 | {From, logon, Name} -> |
@@ -734,7 +731,7 @@ server_logoff(From, User_List) -> |
734 | 731 | lists:keydelete(From, 1, User_List). |
735 | 732 |
|
736 | 733 |
|
737 | | -%%% Server transfers a message between user |
| 734 | +%%% Server transfers a message between users |
738 | 735 | server_transfer(From, To, Message, User_List) -> |
739 | 736 | %% check that the user is logged on and who he is |
740 | 737 | case lists:keysearch(From, 1, User_List) of |
@@ -894,7 +891,7 @@ call. This would result in the process getting bigger and bigger for every loop. |
894 | 891 |
|
895 | 892 | Functions in the `lists` module are used. This is a very useful module and a |
896 | 893 | study of the manual page is recommended (`erl -man lists`). |
897 | | -`lists:keymember(Key,Position,Lists)` looks through a list of tuples and looks |
| 894 | +`lists:keymember(Key,Position,List)` looks through a list of tuples and looks |
898 | 895 | at `Position` in each tuple to see if it is the same as `Key`. The first element |
899 | 896 | is position 1. If it finds a tuple where the element at `Position` is the same |
900 | 897 | as `Key`, it returns `true`, otherwise `false`. |
@@ -986,7 +983,7 @@ From ! {messenger, stop, you_are_not_logged_on} |
986 | 983 |
|
987 | 984 | This is received by the client, which in turn does [`exit(normal)`](`exit/1`) |
988 | 985 | and terminates. If `keysearch` returns `{value,{From,Name}}` it is certain that |
989 | | -the user is logged on and that his name (peter) is in variable `Name`. |
| 986 | +the user is logged on and that their name (peter) is in the variable `Name`. |
990 | 987 |
|
991 | 988 | Let us now call: |
992 | 989 |
|
|
0 commit comments