Home
Getting Started
Contents
1. e Bindings made to variables are remembered e Changes made to the local process dictionary get and put are remembered e New bindings and changes to the local process dictionary are lost if an expression is entered and its evaluation fails In this case the old values are restored e Jobscan be manipulated in the shell A job can be thought of as a set of processes which can communicate with the shell The shell can run in two separate modes e Normal mode in which commands can be edited and expressions evaluated e Job control mode JC L in which jobs can be started stopped detached or connected Only the current job can communicate with the shell Editing Commands The shell supports a sub set of the Emacs line editing commands These commands are listed in the following table Note The notation C a means pressing the control key and the letter a simultaneously M f means pressing the ESC key followed by the letter f The Esc key is also called the M eta key in the Unix environment Getting Started 7 Chapter 1 Getting Started Table 1 1 Text Editing Shell Intemal Commands The shell has a number of built in internal commands The command help displays the following commands 1 helpO shell internal commands bO display all variable bindings e N repeat the expression in query lt N gt 0 forget all variable bindings h history v N use the value of query lt N gt
2. test erl 11 unbound variable Y test erl 11 unbound variable Z The reason for these errors are that the variables Y and Z are undefined The following example shows the use of unsafe variables test1 X gt case f X of true gt X 1 Y 2 false gt X 2 end g x Y In this example there are two possible execution paths in the case statement In one case the variables X and Y are bound in the other case only the variable X is bound After the case statement we can only be certain that X is bound and the variable Y is said to be unsafe Any subsequent use of Y will result in an unsafe variable error message In this case the following compiler error is generated testl erl 15 unsafe variable Y If no reference to Y is made after the case statement the function is correct as the following example shows test2 X gt case f X of true gt X 1 Y 2 false gt X 2 end gr Getting Started 15 Chapter 1 Getting Started Missing Functions The following module contains a missing function module test export test 1 test X gt try X abc When the module is compiled it results in the following gt c test test erl 25 Missing function test try 2 Debugging with the Process Manager The Process M anager pman is a tool which traces the evaluation of code It can trace several different processes and several different machines if distributed Erlang is used pman is con
3. D etailed explanations of the individual commands are included host prompt erl Eshell V4 4 abort with G 1 Str abcd abcd Command 1 sets the variable Str to the string abcd Remember that isthe shorthand for the list of ASCII integers which represents the string 2 L length Str 4 Command 2 matches the pattern L against the return value of length Str Since L is unbound the match succeeds and L is bound to 4 3 Descriptor L list to atom Str 14 abcd Command 3 binds the value of variable Descriptor to the tuple 4 abcd 4 gt L Li Command 4 prints the value of the variable L Getting Started 9 Chapter 1 Getting Started 5 gt b0 Descriptor 4 abcd L 4 Str abcd ok Command 5 evaluates the shell internal command b short for bindings This prints a list of the current shell variables and their bindings 6 L ok Command 6 evaluates the shell internal command f L short for forget which forgets the value of the variable L 7 bO Descriptor 4 abcd Str abcd ok Command 7 returns a list of the current variable bindings The variable L has been forgotten 8 gt IL _ Descriptor 4 abcd Command 8 performs a pattern matching operation on Descriptor binding a new value to L 9 L 4 Command 9 evaluates L and prints its value 10 P Q R Descriptor exited badmatch 4 abcd erl_eval expr 3 C
4. When this is the case we use the term node nameto refer to a node the name of which may be short or long The first part of a node name which comes before the 9 character is the plain name of the node The plain name for a node is unique within the host on which the node is running W hen starting distributed Erlang with either the name or the sname flag the plain name of the node is provided by the user The other part of the node name which isthe host name part is added by the Erlang system at start up Start Up Execute the following command to start a distributed Erlang node 4 erl name foobar Eshell V4 4 abort with G foobar super eua ericsson se 1 gt The node name shown in the system response includes the long name for the host An alternative way is to start the system with the sname flag This is sometimes the only way to run distributed erlang if the Domain Name System DNS is not running or is not available Distribution Script Flags The executable script erl starts the Erlang runtime system Refer to the Reference M anual er1 1 for a complete list of the flags which can be added to the start script This section describes some of the flags which control the distribution e name Name This flag makes the node into a distributed node It invokes all network servers which are needed to make a node a distributed node Refer to the Reference M anual net_kernel 3 for full details The name of the node will b
5. commands in module c c File compile and load code in File cd Dir cd Dir example cd flush flush any messages sent to the shell help help info iO information about the system ni information about the networked system i X Y X information about pid lt X Y Z gt l File Load module in File lc File Compile a list of Erlang modules 1sQ list files in the current directory ls Dir list files in directory lt Dir gt m which modules are loaded m Mod information about module lt Mod gt nc File compile and load code in lt File gt on all nodes nl File Load module in lt File gt on all nodes pid X Y Z convert X Y Z to a Pid Getting Started 1 1 Getting Started with Erlang pwd print working directory regs information about registered processes nregs information about all registered processes commands in module i interpreter interface ihO print help for the i module true 2 W hen an expression with the format Func Argi Arg2 ArgN is entered the shell has to determine what Func refers to before the expression can be evaluated It interprets Func in the following order of priority 1 Func refers to a functional object Fun 2 Func refersto a built in function BIF 3 user default Func in the module user default 4 shell default Funcin the module shell default Example Dialogue with the Shell Thefollowing is an extended dialogue with the shell
6. user_default and shell_default Functions in the shell which are not prefixed by a module name are assumed to be functional objects Funs built in functions BIFs or belong to the module user_default Or shell_default To include private commands define them in a module user default and add the following argument as the first line in the erlang file code load abs user default enr If the contents of erlang are changed and a private version of user default is defined it is possible to customize the Erlang environment M ore powerful changes can be made by supplying command line arguments in the start up script er1 Refer to the Reference M anual er1 1 and init 3 for further information 22 Getting Started List of Figures C hapter 1 Getting Started 11 1 2 1 3 1 4 1 5 The Erlang Toolbar eiu ora ta ee KEY We an Erlang menu on Windows nn 7 The pman Window auci Kaserne nn mg WS E Eg duode 16 The Shell Tracer Window 2 aaa 18 Trace of the Function listsl reverse es 18 Getting Started 23 List of Figures 24 Getting Started List of Tables C hapter 1 Getting Started LX lt TeXt BANG x e a eei beu b AAA re 1 2 The Cl Commands ss ass ss iS a ea hen Getting Started 25
7. G etting Started version 4 8 OTP Team 1998 01 22 Typeset in IATEX from SGML source using the DOCBUILDER 3 0 Document System Contents 1 Getting Started 1 1 1 Getting Started with Erlang 0 o e eee 2 Introductionis aa ar 222 in er le Sese E car D irse ead he 2 Working with Erlang pa to E a AA 3 Th Erl ng Shell z s ta A B AR Rae 6 COMPING 2 52 a dd E 14 Debugging with the Process M anager o e e e 16 Distrib ted Erlang xx a A A a IRA RR 18 Configuration ux 25 A A ee ea Ae ek wee eB AA 22 List of Figures 23 List of Tables 25 Getting Started i Getting Started Chapter 1 Getting Started Getting Started 1 1 Getting Started with Erang Introduction This chapter describes the most common tasks users perform in the Erlang D evelopment Environment or O pen T elecom Platform and is intended for readers who are running Erlang for the first time It also contains references to more detailed information This manual assumes that you have another source of information about how the language Erlang works The first chapter of the book erlbook2 is available online in PDF format This manual will describe how to e compile and run Erlang programs e Work with the Erlang shell this isthe most central part of the development environment e usethe basic tools the debugger and process manager This manual will also describe differences in development environment on the Unix
8. and Windows platforms Note This manual will not describe how to use xerl X erl is a more integrated development environment with an integrated editor and an Erlang shell X erl has some buttons and menus to control the Erlang shell to start other tools and to find manual pages Thisisan old tool that only work on Unix systems and is currently included for backward compatibility with older releases It will be removed or completely rewritten in a future release Manual conventions The following conventions are used to describe commands which are entered from the keyboard in the Erlang shell or on the Emacs command line window based e to enter the command C c Press the C ontrol key and the letter c simultaneously C c is equivalent to c e to enter the command M f Press and release the Esc key then press the letter f e to enter the command halt Enter halt and then pressthe Return key You must include the full stop that terminates the command e the Unix prompt is gt e the dos prompt isC gt IURL http www erlang org download erlang book part1 pdf 2 Getting Started 1 1 Getting Started with Erlang Working with Erlang Erlang programs are executed when you instruct the Erlang Runtime System to execute your code They do not run as binary programs which can be executed directly by your computer The Erlang Runtime System consists of an Erlang evaluator and Erlang libraries The Erlang evaluator is often re
9. e Name Host where Host is the fully qualified host name of the current host This option will also ensure that the Erlang port mapper daemon epmd runs on the current host before Erlang is started Refer to the Reference M anual epmd 3 20 Getting Started 1 1 Getting Started with Erlang e sname Name This flag is the same as the name flag except for the host name used The name of the node will be Name Host where Host is the short host name of the current host If the Domain N ame System DNS is not running this is sometimes the only way to run distributed Erlang Systems The sname flag cannot communicate with systems running with the name flag since node names must be unique in distributed Erlang setcookie Cookie Thisflag sets the magic cookie of the current node to Cookie Since erlang set_cookie node Cookie is used all other nodes are assumed to have their cookies Set to Cookie as well This way several nodes can share a common magic cookie see the next section Security page 21 connect_all false This flag causes the node connection graph to become leaner Only direct connections are established Security Erlang nodes are protected by a magic cookie system Refer to the Reference M anual section kernel the module auth 3 for detailed information about the magic cookie system 1 When a message is sent from one node to another node the sending node attaches the magic cookie of the receiving node to the me
10. e result is the same For a function with side effects the result can be different In the next command it is assumed that test1 loop N is defined in the following way loop N gt io format Hello Number w n N loop N 1 12 Getting Started 1 1 Getting Started with Erlang We continue with command 30 30 testi loop 0 Hello Number 1 Hello Number 2 Hello Number 3 Hello Number 4 Hello Number 5 User switch command gt Command 30 evaluates test1 10oop 0 which puts the system into an infinite loop The user typed Control G This suspends output from the current process which is in a loop and entersJCL mode In JCL mode you can start and stop jobs 31 gt F fun X gt 2 X end Fun lt erl_eval gt 32 gt F 2 4 Command 31 binds the variable F to a fun and command 32 evaluates the expression F 2 Advanced Shell Usage J ob Control Mode W hen the shell starts it starts a single evaluator process This process together with any local processes which it spawns is referred to as a job Only the current job which is said to be connected can perform operations using standard I O All other jobs which are said to be detached will be blocked if they attempt to use standard 1 0 Jobs which do not use standard I O run in the normal way Typing Control G detaches the current job and the shell enters into JCL mode The prompt changes and looks as follows Typing at the prompt givest
11. ed or for systems which are run for maintenance purposes only Refer to the Reference M anual auth 3 for details on the security system Getting Started 21 Slave Nodes The Erlang library module slave provides functionality to start or control slave nodes This functionality is Unix specific The remote nodes are started by means of the Unix command rsh However to use this command the user must not only use a Unix system but must also be allowed to rsh to the remote hosts without being prompted for a password Refer to the following manuals for additional information e The Unix documentation set rsh 1 e The Reference M anual slave 3 Configuration The standard Erlang system can be re configured to change the default behavior on start up The erlang Start up File W hen Erlang is started the system searches for a file named erlang in the directory where Erlang is started If not found the user s home directory is searched for an erlang file If an erlang file is found it is assumed to contain valid Erlang expressions These expressions are evaluated as if they were input to the shell A typical erlang file contains a set of search paths for example io format executing user profile in HOME erlang n code add_uc spy code add_uc pxw code add uc string code add uc unix code add uc pretty format code add_uc iv20 code add_uc string io format erlang rc finished n
12. ferred to as an emulator and is very similar to the J ava virtual machine The Erlang Runtime system together with a basic set of tools for software development form the product The Erlang D evelopment Environment O n top of the Erlang D evelopment Environment an advanced set of tools can be added to form the The O pen Telecom Platform The most central part of the Erlang development environment is the Erlang shell erl erl is available on Unix systems Windows NT and Windows 95 It looks very similar to a Unix shell Windows DOS box or a Windows NT Command box The difference is that the Erlang command line interface understands how to e compile and load Erlang programs e run Erlang programs individual functions or evaluate Erlang expressions e monitor and control execution of the programs e command line editing e history list with previously entered commands In addition to this text based interface there are several window based tools like debugger process manager and database visualizer Y ou can access everything from this command interface but you can also activate the graphic toolbar where you get buttons to start the window based tools Running Erlang To start the Erlang development environment on a Unix system you execute in a Unix shell gt erl s toolbar On the Windows platform you should find Erlang in the start menu usethe entry Erlang with Toolbar If the Erlang executable is in your execution path you can also star
13. he following help message c nn connect to the current job i nn interrupt job k nn kill job j list all jobs S start new job r node start a remote shell q quit erlang h help Getting Started 13 Chapter 1 Getting Started TheJCL commands have the following meaning c Connect to the current job The standard shell will be resumed Operations which use standard 1 0 will be interleaved with user inputs to the shell As above but only for job number nn k Kill the current job All spawned processes in the job will be killed provided they have not evaluated the group 1eader 2 primitive and provided they are located on the local machine Processes spawned on remote nodes will not be killed As above but specifically only for job number nn List all jobs A list of all known jobsis printed The current job name is prefixed with gi Start a new job This will be assigned a new index nn which can be used for referencing r node Start a remote job on node This is used in distributed Erlang to allow a shell running on one node to control a number of applications running on a network of nodes Quit Eran Table 1 2 TheJCL Commands Compiling A file is compiled by evaluating the function compile file File Options File is a file name and Options isa list of compiler options Refer to the Reference M anual for a complete list of Options You can also enter the command c File from
14. lementations of Erlang but it is always an atom which consists of two parts separated by an 9 character The following is an example of a node name dilbert super du ericsson se Before we can fully account for the structure of anode name we have to consider how host names are specified Host Names Every host which is attached to a network has an IP address However it is not practical to use IP addresses when referring to hosts since they are made up of numeric strings which are difficult to remember For this reason hosts are usually given names H ost names of hosts which are connected to the Internet are organized into domains Domains are built hierarchically with top level domains and sub domains For example the domain denoted by du etx ericsson se is asub domain which is part of another sub domain etx ericsson se which is part of thetop domain se When it is clear from the context what domain a host belongs to it is not necessary to use the fully qualified host name In the example super du ext ericsson se the first part super will suffice We refer to super as the short host name of the host H osts which are not connected to the Internet and do not belong to any particular domain are simply referred to by their short host name super for example Weusethe term host nameto denote the name of hosts It should be clear from the context if we mean the long or the short form of the name Node Names A
15. mmands and Erlang expressions which are entered in the shell window are interpreted by the Erlang evaluator In the shell it is possible to e evaluate expressions e recall previous expressions e create or destroy variable bindings e manipulate concurrent jobs D epending on your preferred working environment start Erlang in one of the following ways e Ona Unix system you enter the command erl at the operating system prompt This command starts the Erlang runtime system and the Erlang shell e Onthe Windows platform you normally start Erlang from the start menu Y ou can also enter the command erl or werl from a DOS box or Command box Note that starting with er1 will give you a more primitive Erlang shell than if you start with wer1 see the werl reference manual for details 2URL http www erlang org download erlang book part1 pdf 3URL http www erlang se erlang sure main products doc doc 6 Getting Started 1 1 Getting Started with Erlang sg ea ee 3 Enhanced Keyboard Manager gt 3 Erlang OTP 4 6 1 gt E Erlang OTP 4 6 3 us HyperSnap DX gt 3 Erlang with Toolbar us Microsoft Visual C 5 0 gt P ReadMe Le Netscape Communicator gt 49 Norton Utilities NT gt Ls Startup gt Le SuperClip gt ug WebPhone gt gl Winzip La Winzip Self Extractor Figure 1 2 Erlang menu on Windows A part from evaluation commands and expression the shell hasthe following properties
16. n Erlang node name is an atom constructed as the concatenation of a name supplied by the user the character and the name of the host where the Erlang system is executed For example dilbert super du etx ericsson se In this example dilbert is the name of the Erlang node and super du etx ericsson se is the name of the host where Erlang is running Distributed Erlang requires host names to be unique since Erlang nodes identify each other by node names W e can achieve uniqueness for host names either by using long host names or using short host names with the additional requirement that communicating hosts belong to the same domain or a network not connected to Internet W hen using long host names the corresponding node names are called long node names For example dilbert super du etx ericsson se Getting Started 19 Chapter 1 Getting Started In this case distributed Erlang is started with the name flag The system checks that the host name part of the node name contains at least one dot If not the host name is considered to be in error Similarly when using short host names the corresponding node names are called short node names For example dilbert super In this case distributed Erlang is started with the sname flag Note An Erlang started with along node name cannot communicate with a node started with a short node name It is often clear from the context if a node name is long or short
17. n pressthe Return key 3 Enter the command C g and then press the Return key This command returns with gt press q to quit and then pressthe Return key to abort Erlang Y ou can start various tools from the toolbar Erlang Tools File Tools Help Figure 1 1 The Erlang Toolbar 4 Getting Started 1 1 Getting Started with Erlang Compiling a File This section describes how to compile and run a simple Erlang program using the Erlang shell It is assumed that the following program which calculates the factorial of an integer has been created with an external editor and saved with the file name math1 er1 M ake sure that you are in the directory where the program file is stored Use the command pwd to check this and if needed change directory by using the command c Dir module math1 export factorial 1 factorial 0 gt 1 factorial N gt N factorial N 1 Follow these stepsto compile the program 1 Enter the command c math1 1 c math1 ok math1 2 gt 2 The system returns ok math1 if the compilation was successful If unsuccessful the compiler prints an error message in the following format mathi erl line number error message Refer to the section Compiling page 14 in this chapter for more information about compiling code Evaluating an Expression W hen a module has been successfully compiled the exported functions in the module can be evaluated by e
18. ntering the expression at the Erlang shell prompt followed by a full stop and a carriage return The following example illustrates an evaluation using the math1 er1 program e Enter the following expression at the command prompt mathi factorial 45 e Erlang evaluates the expression and prints the result The result from the expression entered looks as follows 2 mathi factorial 45 119622220865480194561963161495657715064383733760000000000 3 gt Note All Erlang expressions must end with a full stop Getting Started 5 Chapter 1 Getting Started Aborting Evaluation of an Expression Enter C c to abort an evaluation press the C ontrol key and the letter c simultaneously This action will also terminate an infinite loop How to get help The Erlang language itself is described in the book erlbook2 which is available online in PD F format The complete documentation is part of the release in HTML format The top of the documentation tree is located in the doc directory of the Erlang installation It is also available on line From an Unix shell you can access the manual pages for the Erlang libraries As an example to display the manual page for the module titled lists you enter 4 erl man lists You can list the shell commands from the Erlang shell if you enter 1 helpO The Erlang Shell The Erlang Shell is a program which provides a front end to the Erlang evaluator Edit commands shell internal co
19. ommand 10 triesto match P Q R against Descriptor which is 4 abc The match fails and none of the new variables are bound exited badmatch isprinted Thisis not the value of the expression and the expression has no value since its evaluation failed It isa warning printed by the system to inform you that an error has occurred The information printed after the word badmatch indicates which term was being matched and in which function the error occurred The values of all other variables such as L and Str are unchanged 11 P exited unbound P erl_eval expr 3 10 Getting Started 1 1 Getting Started with Erlang 12 gt Descriptor 14 abcd Commands 11 and 12 show that P is unbound as the previous command failed and Descriptor has not changed 13 gt IP Q Descriptor 14 abcd Commands 13 and 14 show successful matches in which P and Q are bound 15 gt fO ok Command 15 clears all bindings For the next commands we assume that test1 demo X is defined in the following way testi demo X gt put aa worked X 1 X 10 16 put aa hello undefined 17 get aa hello Commands 16 and 17 set and inspect the value of the item aa in the process dictionary 18 Y test1 demo 1 11 19 get aa worked Command 18 evaluates test1 demo 1 the evaluation succeeds and the changes made in the process dictionary become visible to the shell The new
20. ssage 2 Theruntime system on the receiving node verifies that the magic cookie is the correct one for this node 3 If the magic cookie is correct the message is accepted If the magic cookie is not correct then the message is handled as follows e The message is transformed into a badcookie message e The badcookie message is sent to the system process net kernel e By default the net kerne1 passes the message to the registered process auth e The auth process is then responsible for taking appropriate action for the unauthorized message In the standard system the default action is to shut down the connection to the sending node M agic cookies are assigned to a node as follows 1 Initially each node is assigned a random atom as its magic cookie and each node assumes the atom nocookie for all other nodes 2 When the standard auth server is started without the setcookie flag it reads a file named HOME erlang cookie If the file HOME erlang cookie does not exist it is created with a random string as its content The permission mode of the file is set to read only by owner 3 The system creates an atom from the contents of this file and the function erlang set cookie node CookieAtom setsthe magic cookie for the node to the value of this atom An Erlang system is completely unprotected when running erlang set_cookie node nocookie This can sometimes be appropriate for systems that are not normally network
21. t Erlang from a DOS box or NT command line with C gt werl s toolbar Note On the Windows platform there are two executables er1 and wer1 You normally use wer1 see the werl reference manual for details The following apears on the screen Getting Started 3 Chapter 1 Getting Started Erlang JAM emulator version 4 6 Eshell V4 6 abort with G 1 gt The Erlang shell is now ready for you to type some input The commands you enter could be any Erlang expression which is understood by an Erlang shell Try it out by typing 1 2 followed by pressing the return key don t forget the terminating dot You can also call one of the built in functions type date O The result from what you entered should make it look like Erlang JAM emulator version 4 6 Eshell V4 6 abort with G 1 gt 1 2 3 2 gt date 1998 1 22 The example above can be regarded as having a dialog with the runtime system You can also run functions or programs send messages or monitor processes To stop Erlang enter one of the following commands in the window where Erlang was started 1 Enter the command C c press the C ontrol key and the letter c simultaneously This command puts Erlang into BREAK mode and the system responds as follows BREAK a bort c ontinue p roc info i nfo 1 oaded v ersion k ill D b tables d istribution Enter a and then press the Return key to abort Erlang 2 Enter the command halt and the
22. the Erlang shell This command assumes that the following conditions apply 1 The module name is the same asthe file name minusthe er1 extension 2 Codeisto be loaded immediately if the compilation succeeds The function make all can be used to compile many files All files must be located in the same directory Refer to the Reference M anual function make 3 for full details Compiler Diagnostics The Erlang compiler detects a number of different errors These can be e Syntax errors e variable Errors e missing function errors The compiler also warns about potential errors 14 Getting Started 1 1 Getting Started with Erlang Syntax Errors Syntax errors are reported against syntactically incorrect Erlang code For example the following code fragment is incorrect and will be reported by the compiler as shown test X Y gt case g X o Y gt dg 2 gt 2 end The syntax word of in the case construction is incorrectly spelt This produces the compiler diagnostic testi erl 10 of expected before o This means that an error occurred in line 10 of the file test1 er1 The message which follows the line number describes the error Variable Errors Two types of variable errors can be detected by the compiler V ariables can be undefined or unsafe In the following example the variables Y and Z are undefined test X gt A f X Y Z b A X W hen compiled the following error messages are printed
23. tion listsl reverse page 18 Note All traced modules must be compiled in trace mode Getting Started 17 Chapter 1 Getting Started Er Lies race I velat a parsaluatar 3 current fanctigs shell evsl Toon miaj dra 34 rtark 61561 53 dert aman 4 Vinter L Zp 28 83 apesta foa Figure 1 4 The Shell Tracer Window ita jim race rial salir anal ieee luatar a current fanctigs shell evsl loop LI A tack se 53 dottinn 4 Viste L p 28 1 apeiti fana b Kati ir ratt z pal Fi rmi ez Lat 2 cab Tirtrlirev ruel s re Tietaiireverges sare 11 listarirevargel neg al Tixtzri rwvmramitci ha Tixtsl revergei d chy Vistas ser ich Figure 1 5 Trace of the Function listsl reverse Distributed Erlang Erlang can be used to write distributed applications which run simultaneously on several computers Programming distributed systems with Erlang is the subject of the book erlbook2 Refer also to the Reference M anual 18 Getting Started 1 1 Getting Started with Erlang Nodes A node is a basic concept of distributed Erlang In a distributed Erlang system the term node means an executing Erlang system which can communicate with other Erlang systems Each node has a name assigned to it which is returned by the built in function node O This name is an atom and is guaranteed to be globally unique The format of the name can vary between different imp
24. trolled through a simple graphical user interface Start pman as follows e run the function pman start from the Erlang shell e push the debugger button on the Toolbar The following window is displayed when starting the pman Hids Serben processes Y Murta Birle Ass Figure 1 3 The pman Window This section describes a simple debugging example which involves tracing the code in a single process For a more detailed description of pman see the User s M anual 16 Getting Started 1 1 Getting Started with Erlang Tracing a Single Function We illustrate the use by tracing the evaluation of the function 1istsi reverse which is defined as follows module listsi export reverse 1 reverse X gt reverse X reverse HIT L gt reverse T HIL reverse L gt L Follow these steps to trace this process 1 Select the Shell Process item in the Trace menu of the pman main window The window shown in The Shell Tracer Window page 18 is displayed 2 From the shell tracer window select the O ptions item in the File menu Select the Trace functions check box and click OK 3 The first command c lists1 trace compiles the module 1ists1 in trace mode 1 c listsi trace ok listsi 4 Evaluate the function lists1 reverse abcd 2 listsi reverse abcd dcba 5 The contents of the shell trace window changes to show a listing of the called functions See Trace of the func
25. value of the dictionary item aa can be seen in command 19 Getting Started 11 Chapter 1 Getting Started 20 gt put aa hello worked 21 Z test1 demo 2 Error in process 0 17 0 with exit value badmatch 1 test1 demo 2 exited badmatch 1 test1 demo 2 Commands 20 and 21 reset the value of the dictionary item aa to hello and calls test1 demo 2 The evaluation fails and the changes made to the dictionary in test1 demo 2 before the error occurred are discarded 22 Z exited unbound Z erl_eval expr 3 23 gt get aa hello Commands 22 and 23 show that Z was not bound and that the dictionary item aa retained its original value 24 gt erase put aa hello undefined 25 spawn testi demo 1 0 15 1 26 get aa hello Commands 24 25 and 26 show the effect of evaluating test1 demo 1 in the background In this case the expression is evaluated in a newly spawned evaluator and any changes made in the process dictionary are local to the newly spawned process and therefore not visible to the shell 27 io format hello hello n hello hello ok 28 e 27 hello hello ok 29 v 27 ok Commands 27 28 and 29 usethe history facilities of the shell Command 28 is e 27 which re evaluates command 27 Command 29 is v 27 which usesthe value result of command 27 In the case of a pure function i e afunction with no side effects th
Download Pdf Manuals
Related Search
Related Contents
Manual Técnico Liger Universal - Rev0.indd Giant Revive User's Manual Power Perch User`s manual - Featherweight Altimeters Bedienungsanleitung inyección gasolina - Automotriz En Video TE-6.5 Series Criterion Particulate Spectrometer Analyzer Manual Kingston Technology ValueRAM KVR16R11D8/8I memory module HI 839800 COD REACTOR and Test Tube Heater 2008 Series Copyright © All rights reserved.
Failed to retrieve file