My top 5 Favourite Erlang Functions
Tuesday, September 2, 2008 at 12:56 by
Jón Grétar Borgþórsson Well.. After playing around in Erlang for a short while I wanted to share some newly discovered gems. These are my new favourite functions. I challenge some more experienced Erlang programmers to post theirs. I selected here some debugging tools that you just use in the shell but there are a lot more gems available.
nc/1 and nc/2
Remember c().? The command you use to compile code from the Erlang shell. Well nc/1 compiles and loads the code in all connected nodes. The source doesn't even need to exist in the remote nodes. Just try it by creating a bunch of nodes and typing nc(modulename). in one of them.
l/1 and nl/1
l/1 simply runs code:purge/1 and code:load_file/1 to remove code for a module marked as old. nl/1 does the same except on all connected nodes. Note that code:purge/1 removes old code even if it is in use. Also consider code:soft_purge/1 that only removes old code if no processes use it.
i/0 and ni/0
Another friend for the c module. i/0 gives you a list of processes and some good info on them. A valuable tool. Like you propably guessed the ni/0 function does the same for all the connected nodes.
slave:start/2
When you need to quickly start a bunch of slave nodes you should use slave:start/2. I'm not sure on the difference on those nodes and the regular but it still is a valueable tool when testing things.
toolbar:start/0
There are loads of valuable GUI tools for debugging in Erlang. toolbar:start/0 gives you a quick access to many of them such as the Mnesia Table Visualizer, Process Manager, The Debugger and the Application Monitor. The Table Visualizer by itself is something I use daily. You can also make your own tools into the toolbar. On a related note also check out webtool:start/0 and open up http://127.0.0.1:8888/ and check out how to make your own webtool.




Reader Comments