NEW NEW: I am working on models for building wxErlang interfaces. The code is at http://wxerlang.dougedmunds.com
process tree This code starts with a pid registered as 'top' and allow for building a tree of pids branching off from there. The entries all have values. There is a breadth first search routine at the end of the code.
The 'me' pid is a placeholder. It travels up and down the tree with basic commands like “me ! up” “me ! down”. To add to the tree, position 'me' where the child (kid) should be added.
If a pid is deleted, (using me ! del), the 'kids' are reattached to the 'grandparent'.
Some recursion examples.
I am posting code that simulates a circuit that operates a light, using 3-way switches. I use processes to serve as the circuit breaker (on off), and the switches (flip).
Newbie hints (for Windows users):
- 1) When you want to read about a module in the official docs, click under the top-left icon of the left frame where it says MODULES, then look in the left column, which is alphabetical to find it. But after you find the module, ALWAYS click the library entry in the right column. If you pick the right column, you will get frames, which lets you navigate better.
- 2) Don't bother to try to figure out why some modules are in stdlib and others are in kernel.
- 3) Grab a copy of “Agent Ransack” and learn how to use it. This is like grep on steroids. Get it here: http://www.mythicsoft.com/agentransack/ Another good program is “DocFetcher” at http://docfetcher.sourceforge.net/en/index.html Use these programs to do word searches inside the erlang documentation when the built-in structure fails to find something. Also good for finding words inside the source code.
- 4) Associate .erl files to your text editor, not to erlang. Use a text editor that can open the Erlang shell. I use NotePad++ (not Notepad). I am also looking at Programmer's Notepad 2. Associate your .beam files to erlang (werl.exe).
- 5) Don't put your work files under the Erlang root. If you upgrade to the next version, you may inadvertently delete everything during installation.
- 6) Use io:format(“Variable: ~p~n”,[VARIABLE_HERE]) as a debugging tool.
This wiki provides examples of some Erlang functions (ets and dets). My main target however is to develop examples that show how processes work, because to me the messaging capabilities of Erlang are what distinguish it from other programming languages.
I don't plan to make this public-writable. If you have suggestions, send me an email.
- ets (more complete, start here anyway)
- dets (less complete)
- processes (some how-to test code)
- supermarket example (modeling activity via processes)
- 3-way switches (light switches simulation)
- convert types (i.e., “3” (string to 3 (integer)
- process tree processes linked in a tree
- very miscellaneous holding tank
- All about the GS moduleclick here
- Erlbol, using REBOL as a gui front end to Erlang. click here. Note: use wxWidgets instead.
If you get lost on this site, click the word 'Erlang' at the top or 'start' in the left column.
Also, if you haven't already explored what's on http://trapexit.org, that's probably a better place to start than here. – Doug Edmunds