<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in Programming Erlang | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/27/posts</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <item>
      <title>unix crypt() fun posted by Alain O'Dea @ Wed, 07 May 2008 02:03:01 -0000</title>
      <description>&lt;p&gt;&lt;span class="caps"&gt;OTP R12B&lt;/span&gt; includes the Crypto Application:&lt;br /&gt;&lt;a href="http://www.erlang.org/doc/apps/crypto/index.html"&gt;http://www.erlang.org/doc/apps/crypto/index.html&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m not sure how complete it is. My understanding is that ejabberd includes a more complete OpenSSL implementation which they need for &lt;span class="caps"&gt;SSL&lt;/span&gt; Jabber/XMPP.&lt;/p&gt;</description>
      <pubDate>Wed, 07 May 2008 02:03:01 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:391:2746</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/391</link>
    </item>
    <item>
      <title>Erlang Python Example posted by Alain O'Dea @ Wed, 07 May 2008 02:00:05 -0000</title>
      <description>&lt;p&gt;Very nice Stephan. Thank you for posting that. I was looking for a cleaner way to do communication between Erlang and Python. I could not figure out how to make Python implementation for the ports example.&lt;/p&gt;


	&lt;p&gt;Until now I have been using &lt;span class="caps"&gt;TCP&lt;/span&gt;/IP line-based communication. I could not figure out how to get the packet size thing to work. If you are interested I have included my old approach below.&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;TCP&lt;/span&gt; line-based integration with Erlang:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;-module (echo_server).
-export([start/0]).

start() -&amp;gt;
    {ok, Listen} = gen_tcp:listen(4321, [list, {packet, line},
                                         {reuseaddr, true},
                                         {active, true}]),
    spawn(fun() -&amp;gt; par_connect(Listen) end).

par_connect(Listen) -&amp;gt;
    {ok, Socket} = gen_tcp:accept(Listen),
    spawn(fun() -&amp;gt; par_connect(Listen) end),
    io:format("Client connected~n"),
    echo(Socket). 

echo(Socket) -&amp;gt;
    receive
        {tcp, Socket, Line} -&amp;gt;
            gen_tcp:send(Socket, Line),
            echo(Socket);
        {tcp_closed, Socket} -&amp;gt;
            io:format("Client disconnected~n")
    end.&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;Telnet can then be used to test the interface: &lt;code&gt;telnet 127.0.0.1 4321&lt;/code&gt;. Once you are satisfied it is very easy to build a &lt;span class="caps"&gt;TCP&lt;/span&gt; client in Python. I used this to implement a very basic Erlang code completion server for use with TextMate.&lt;/p&gt;</description>
      <pubDate>Wed, 07 May 2008 02:00:05 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:390:2745</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/390</link>
    </item>
    <item>
      <title>Some question about Chapter.14 (How to execute string) posted by Alain O'Dea @ Wed, 07 May 2008 01:33:05 -0000</title>
      <description>&lt;p&gt;&lt;strong&gt;lib_misc:string2value/1&lt;/strong&gt; is implemented as follows:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;string2value(Str) -&amp;gt;
    {ok, Tokens, _} = erl_scan:string(Str ++ "."),
    {ok, Exprs} = erl_parse:parse_exprs(Tokens),
    Bindings = erl_eval:new_bindings(),
    {value, Value, _} = erl_eval:exprs(Exprs, Bindings),
    Value.&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;I could not find a direct equivalent to Python&amp;#8217;s &lt;strong&gt;exec&lt;/strong&gt; statement in the modules shipped with Erlang &lt;span class="caps"&gt;OTP R12B&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;The entire set of example code for Programming Erlang is available for download here:&lt;br /&gt;&lt;a href="http://www.pragprog.com/titles/jaerlang/source_code"&gt;http://www.pragprog.com/titles/jaerlang/source_code&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 07 May 2008 01:33:05 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:384:2744</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/384</link>
    </item>
    <item>
      <title>unix crypt() fun posted by Marco Romano @ Mon, 28 Apr 2008 13:00:54 -0000</title>
      <description>&lt;p&gt;Hello folks,&lt;/p&gt;


	&lt;p&gt;do you know if exist an erlang implementation of unix crypt() function ? Thanks.&lt;/p&gt;</description>
      <pubDate>Mon, 28 Apr 2008 13:00:54 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:391:2662</guid>
      <author>Marco Romano</author>
      <link>http://forums.pragprog.com/forums/27/topics/391</link>
    </item>
    <item>
      <title>Erlang Python Example posted by Stephan Nies @ Mon, 28 Apr 2008 12:22:33 -0000</title>
      <description>&lt;p&gt;Hello, &lt;br /&gt;I am just learning Erlang. But since much of my&lt;br /&gt;codebase is in Python i wanted to interface Erlang and&lt;br /&gt;Python. So i ported the ports example in Chapter 12.1 to Python.&lt;/p&gt;


	&lt;p&gt;I thought that might be of interest for some other &lt;br /&gt;people using Erlang and Python. So here is the link:&lt;/p&gt;


	&lt;p&gt;&amp;#8220;http://www.physik.uni-dortmund.de/~nies/example1.py&amp;#8221;&lt;/p&gt;


	&lt;p&gt;You can just use it as a replacement for the C-code,&lt;br /&gt;just make sure to rename it to example1, make it executeable&lt;br /&gt;and place it in the same dir as example1.erl&lt;/p&gt;


	&lt;p&gt;Oh and while searching the net for python &amp;lt;-&amp;gt; erlang examples&lt;br /&gt;I found this neat project using twisted to interface with erlang: &lt;a href="https://launchpad.net/twotp"&gt;https://launchpad.net/twotp&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Cheers,&lt;br /&gt;Stephan&lt;/p&gt;</description>
      <pubDate>Mon, 28 Apr 2008 12:22:33 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:390:2661</guid>
      <author>Stephan Nies</author>
      <link>http://forums.pragprog.com/forums/27/topics/390</link>
    </item>
    <item>
      <title>Some question about Chapter.14 (How to execute string) posted by Yuichi Ito @ Fri, 25 Apr 2008 07:27:36 -0000</title>
      <description>&lt;p&gt;Hello.&lt;br /&gt;I want to execute the code of Chap14 &amp;#8220;start_nano_server()&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;But there is no function &amp;#8220;lib_misc:string2value(String)&amp;#8221;.&lt;br /&gt;So, I checked this book&amp;#8217;s index(reference?), and searched in Google.&lt;br /&gt;But couldn&amp;#8217;t find both.&lt;/p&gt;


	&lt;p&gt;this function acts like this&lt;br /&gt;&amp;gt; lib_misc:string2value(&amp;#8220;list_to_tuple([2+3*4,10+20])&amp;#8221;).&lt;br /&gt;{14,30}&lt;/p&gt;


	&lt;p&gt;How do I create this function?&lt;br /&gt;Or, is there a function which execute string like Python&amp;#8217;s &amp;#8220;exec Statement&amp;#8221;?&lt;/p&gt;


	&lt;p&gt;Thsnks&lt;br /&gt;(I&amp;#8217;m using Japanese editon, so there may be little difference in English edition)&lt;/p&gt;</description>
      <pubDate>Fri, 25 Apr 2008 07:27:36 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:384:2635</guid>
      <author>Yuichi Ito</author>
      <link>http://forums.pragprog.com/forums/27/topics/384</link>
    </item>
    <item>
      <title>Erlang control Java? posted by Alain O'Dea @ Wed, 02 Apr 2008 03:15:49 -0000</title>
      <description>&lt;p&gt;If you use &lt;code&gt;open_port({spawn, "command"}, [stream])&lt;/code&gt; you will be able to use standard IO streams on the Java side and message send and receive operations on the Erlang side. There is also a &lt;code&gt;line&lt;/code&gt; option which might be useful. Just make sure to use a PrintWriter or some other buffered output stream and call flush() from the Java side to send a message.&lt;/p&gt;


	&lt;p&gt;An Erlang module to dump content into the Mac &lt;span class="caps"&gt;OS X&lt;/span&gt; clipboard using the pbcopy program:&lt;br /&gt;&lt;pre&gt;
copy(Data) -&amp;gt;
    Clipboard = open_port({spawn, "pbcopy"}, [stream]),
    Clipboard ! {self(), {command, Data}},
    Clipboard ! {self(), close},
    receive
        {Clipboard, closed} -&amp;gt; true
    end.
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;If you bring up the Erlang docs for open_port on &lt;a href="http://www.gotapi.com/"&gt;http://www.gotapi.com/&lt;/a&gt; it explains how to communicate with the port.&lt;/p&gt;</description>
      <pubDate>Wed, 02 Apr 2008 03:15:49 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:293:2525</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/293</link>
    </item>
    <item>
      <title>RSA encryption posted by Alain O'Dea @ Wed, 02 Apr 2008 03:06:30 -0000</title>
      <description>&lt;p&gt;Take a look at the ejabberd libraries &lt;a href="http://www.ejabberd.im/"&gt;http://www.ejabberd.im/&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;The ejabberd guys implemented &lt;span class="caps"&gt;SSL&lt;/span&gt; and a bunch of other very useful libs for Erlang.&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;CEAN&lt;/span&gt; &lt;a href="http://cean.process-one.net/packages/"&gt;http://cean.process-one.net/packages/&lt;/a&gt; and Jungerl &lt;a href="http://jungerl.sourceforge.net/"&gt;http://jungerl.sourceforge.net/&lt;/a&gt; are decent sources for stuff like this as well. Jungerl is not for the feint of heart, but they have a lot of projects for wrapping the best of breed &lt;span class="caps"&gt;GNU&lt;/span&gt; and &lt;span class="caps"&gt;BSD&lt;/span&gt; libraries.&lt;/p&gt;</description>
      <pubDate>Wed, 02 Apr 2008 03:06:30 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:295:2524</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/295</link>
    </item>
    <item>
      <title>Chapter 8 Problems posted by Alain O'Dea @ Wed, 02 Apr 2008 02:59:30 -0000</title>
      <description>&lt;p&gt;I posted a reply to your blog, but it was dark and appears to have been eaten by a grue :(&lt;/p&gt;</description>
      <pubDate>Wed, 02 Apr 2008 02:59:30 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:311:2523</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/311</link>
    </item>
    <item>
      <title>Side effect posted by Alain O'Dea @ Wed, 02 Apr 2008 02:57:18 -0000</title>
      <description>&lt;p&gt;My understanding (Joe, correct me if I am wrong), is that the term Side effect is used in the book to mean anything that alters state outside of the current function being executed.&lt;/p&gt;


	&lt;p&gt;All Variables in Erlang are either bound or unbound. Once bound through matching in an expression an Erlang Variable cannot be changed. What appears to be an assignment operator (the &amp;#8221;=&amp;#8221; sign) is in actual fact a constraint expression declaring the left and right hand sides of the expression to be equal.&lt;/p&gt;


	&lt;p&gt;Writing X = 1 followed by X = 2 will fail on X = 2 because X has already been constrained to equal 1 by X = 1. This pattern matching mechanism requires rethinking the design of state and variables in a program. &lt;span class="caps"&gt;IMHO&lt;/span&gt;, the end result is more comprehensible code that is easier to reason about and explain to others.&lt;/p&gt;


	&lt;p&gt;In Erlang an expression cannot directly modify the state of another function or even other expressions in the same scope. All such modifications are explicitly made through the interpretation of messages or function parameters. By Chapter 3 you have not gotten to see Message Passing or Concurrency. It should hopefully be clearer at that point.&lt;/p&gt;


	&lt;p&gt;I check this board frequently so please post your questions here. I will do my best to help :)&lt;/p&gt;</description>
      <pubDate>Wed, 02 Apr 2008 02:57:18 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:298:2522</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/298</link>
    </item>
    <item>
      <title>E is for excellent: Appendix E posted by Alain O'Dea @ Wed, 02 Apr 2008 02:41:37 -0000</title>
      <description>&lt;p&gt;Don&amp;#8217;t forget to read Appendix E. It explains many of the tools that come with Erlang like Code Coverage, Profiler, and Cross-reference analyzers.&lt;/p&gt;


	&lt;p&gt;It also gives a quick overview of the Debugger and debugging technique, provides some explanation of the errors the Compiler generates, and explains how to use the Tracing tool.&lt;/p&gt;


	&lt;p&gt;Seriously, read Appendix E. It takes Erlang programming from a design exercise to a seriously pragmatic and productive endeavor. I went from running mind-experiments of my code to doing unit testing with coverage analysis within an hour of skimming over Appendix E.&lt;/p&gt;


	&lt;p&gt;These tools are all invoked using Erlang code. This makes automating workflows that use them surprisingly easy and convenient.&lt;/p&gt;


	&lt;p&gt;A module called project which I created to handle builds and coverage for a game server I am writing:&lt;br /&gt;&lt;pre&gt;-module(project).
-author('alain.odea').
-license('http://opensource.org/licenses/afl-3.0.php').
-export([make/0, cover/0]).

each(Fun) -&amp;gt;
    lists:map(Fun, [actor, escrow, game, hex, inner_perimeter, 
                    intersection, outer_perimeter, path, player,
                    server, status, stockpile, test_game]).

make() -&amp;gt;
    each(fun(Mod) -&amp;gt; shell_default:c(Mod, [debug_info]) end).

cover() -&amp;gt;
    cover:start(),
    each(fun cover:compile/1),
    test_game:run(),
    each(fun cover:analyse_to_file/1).
&lt;/pre&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 02 Apr 2008 02:41:37 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:347:2521</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/347</link>
    </item>
    <item>
      <title>code:get_path / code:add_path posted by Alain O'Dea @ Sat, 22 Mar 2008 22:52:58 -0000</title>
      <description>&lt;p&gt;The path list can be modified because it is maintained by a separate process. The state around the receive statement in that process can be changed by recursion.&lt;/p&gt;


	&lt;p&gt;code:call/1 invokes code_server:call/1 which sends a message to the code server process. Upon receiving a path addition message the code_server process calls the function that receives code_server commands again recursively with a modified version of the list. Single assignment is preserved in this manner.&lt;/p&gt;</description>
      <pubDate>Sat, 22 Mar 2008 22:52:58 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:284:2476</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/284</link>
    </item>
    <item>
      <title>Chapter 8 Problems posted by Christopher Atkins @ Tue, 11 Mar 2008 01:42:36 -0000</title>
      <description>&lt;p&gt;Hi all!  Man, I&amp;#8217;m loving Erlang.  It&amp;#8217;s nice to be excited about programming again.  Thanks &lt;span class="caps"&gt;JOE&lt;/span&gt;!!&lt;/p&gt;


	&lt;p&gt;I completed &lt;a href="http://iformattable.blogspot.com/2008/03/programming-erlang-chapter-8-problem-2.html"&gt;problem 2&lt;/a&gt;, and I was hoping someone might give me some pointers.&lt;/p&gt;</description>
      <pubDate>Tue, 11 Mar 2008 01:42:36 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:311:2419</guid>
      <author>Christopher Atkins</author>
      <link>http://forums.pragprog.com/forums/27/topics/311</link>
    </item>
    <item>
      <title>Side effect posted by Alexey Kuznetsov @ Thu, 06 Mar 2008 22:41:10 -0000</title>
      <description>&lt;p&gt;I already finish 3 chapters, but still don&amp;#8217;t understand what mean that expression? I know only side effect in C++ or other imperative languages.&lt;/p&gt;</description>
      <pubDate>Thu, 06 Mar 2008 22:41:10 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:298:2395</guid>
      <author>Alexey Kuznetsov</author>
      <link>http://forums.pragprog.com/forums/27/topics/298</link>
    </item>
    <item>
      <title>RSA encryption posted by richard bucker @ Wed, 05 Mar 2008 22:27:36 -0000</title>
      <description>&lt;p&gt;I&amp;#8217;d really like to use openssl&amp;#8217;s &lt;span class="caps"&gt;RSA&lt;/span&gt;_encryption() or the &lt;span class="caps"&gt;RSA&lt;/span&gt;_mod_exp()... but I&amp;#8217;m having a hard time generating the appropriate prime numbers. Seems to me that the openssl integration was only partially completed.&lt;/p&gt;


	&lt;p&gt;Can anyone make recommendations?  What about explaining why the libs are incomplete?&lt;/p&gt;


	&lt;p&gt;/r&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 22:27:36 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:295:2384</guid>
      <author>richard bucker</author>
      <link>http://forums.pragprog.com/forums/27/topics/295</link>
    </item>
    <item>
      <title>Erlang control Java? posted by Chris Liaw @ Wed, 05 Mar 2008 03:50:43 -0000</title>
      <description>&lt;p&gt;Hi,&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;After i read the book of Pragmatic Erlang, i got bought into the Erlang. However, since my previous project is all Java, i do have some Java library which is not available in Erlang such as complete cryptographic library.&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;I am pretty much wanted to use Erlang distributed, concurrency and fault torelant in my program but i also need the java cryptographic library. Hence i am thinking of creating a java program which is capable to be controlled by Erlang.&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;I tried the JInterface, it works but i am exploring to use Java port, which is the IO communication of Java program with Erlang node. However, i can not seems to get it working. Is there any specific steps which i need to do to allow Erlang can send and receive messages via open_port() with Java program?&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;Thanks.&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Regards,&lt;br /&gt;Chris&lt;/p&gt;</description>
      <pubDate>Wed, 05 Mar 2008 03:50:43 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:293:2379</guid>
      <author>Chris Liaw</author>
      <link>http://forums.pragprog.com/forums/27/topics/293</link>
    </item>
    <item>
      <title>code:get_path / code:add_path posted by Mike Lutz @ Mon, 03 Mar 2008 01:56:54 -0000</title>
      <description>&lt;p&gt;code:getpath() returns a list of the current directories searched for modules. This list can be &lt;strong&gt;modified&lt;/strong&gt; by code:add_patha() and code:add_pathz() and a bunch of their cousins. This looks like a violation of the one assignment rule &amp;#8211; otherwise, how can code:get_path() return different values at different times?&lt;/p&gt;


	&lt;p&gt;The source code shows add_patha as:&lt;/p&gt;


	&lt;p&gt;add_patha(Dir) when is_list(Dir) -&amp;gt; call({add_path,first,Dir}).&lt;/p&gt;


	&lt;p&gt;and I can&amp;#8217;t find any documentation on &amp;#8220;call&amp;#8221;, so my suspicion is that it&amp;#8217;s some internal mumbo-jumbo in the interpreter, but I&amp;#8217;d love to have this explained. A form of continuation??&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;MJL&lt;/span&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 03 Mar 2008 01:56:54 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:284:2361</guid>
      <author>Mike Lutz</author>
      <link>http://forums.pragprog.com/forums/27/topics/284</link>
    </item>
    <item>
      <title>2.6 One time assigments posted by Alain O'Dea @ Wed, 27 Feb 2008 00:56:13 -0000</title>
      <description>&lt;p&gt;Iterative or repeating algorithms are fairly easy to port from an imperative language (like Java) to Erlang.&lt;/p&gt;


	&lt;p&gt;For example, you want to gather some interesting property from a set of items.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;In Java you would use a for loop and an accessor method:&lt;/strong&gt;&lt;br /&gt;&lt;pre&gt;
void process(List list) {
    List output = new ArrayList();
    for (Item item : list) {
        output.add(item.getInterestingProperty());
    }
    return output;
}
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;In Erlang you would fold the list and extract the property with pattern matching:&lt;/strong&gt;&lt;br /&gt;&lt;pre&gt;
process(List) -&amp;gt;
    lists:foldl(fun process/2, [], List).

process(#item{interestingProperty=InterestingProperty}, Output) -&amp;gt;
    [InterestingProperty|Output].
&lt;/pre&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 27 Feb 2008 00:56:13 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:275:2336</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/275</link>
    </item>
    <item>
      <title>2.6 One time assigments posted by Joe Armstrong @ Tue, 26 Feb 2008 10:04:34 -0000</title>
      <description>&lt;p&gt;Good question !&lt;/p&gt;


	&lt;p&gt;Erlang has no loops or for/next cycles so the problem does not occur.&lt;/p&gt;


	&lt;p&gt;Basically you cannot say X = X + 1, you have to invent a new variable X1 and make sure that X1 goes &amp;#8220;out of scope&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;So the old code (in an imperative language)&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;foo(X) {
    X = X + 1,
    Y = bar(X),
    ho(X, Y),
    joe(Y).
}&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;becomes&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;foo(X) -&amp;gt; 
    X1 = X + 1,
    Y = bar(X1),
    ho(X1, Y),
    %% At this point X1 is no longer referred to so the space for X1 can  be freed
    joe(Y).&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;We now call joe(Y) but where does joe(Y) return to? &amp;#8211; to the end of foo(X) where it finds a return instruction&lt;br /&gt;ultimately joe(Y) returns to the place that called foo(X) &amp;#8211; the point is that Y is never refereed to again&lt;br /&gt;in the body of foo(X) and can be garbage collected.&lt;/p&gt;


	&lt;p&gt;So we create new variables X1, X2, X3, .... and the space for these can be reclaimed &lt;br /&gt;when the program can no longer access these variables.&lt;/p&gt;


	&lt;p&gt;To get the effect of a loop we write a tail-recursive recursive function. So to sum the integers from 1 to N&lt;br /&gt;we might write.&lt;/p&gt;


	&lt;p&gt;sum(N) -&amp;gt; sum(N, 0).&lt;/p&gt;


	&lt;p&gt;sum(0, Sum) -&amp;gt; Sum;&lt;br /&gt;sum(N, Sum) -&amp;gt;
     Sum1 = Sum + 1,    %% create a new value of Sum
     N1 = N &amp;#8211; 1,        %% and a new value of N
     sum(N1, Sum1).     %% call sum (again)&lt;/p&gt;


	&lt;p&gt;The last line (which calls sum) merely jumps to the start of the sum routine. Although this is a call&lt;br /&gt;the system does not return to site of the call, since this merely returns immediately, instead it returns,&lt;br /&gt;(this is called &amp;#8220;last-call&amp;#8221; optimization). Having jumped to the start of sum the variables&lt;br /&gt;N1 and Sum1 are out of scope and can never be accessed again, so they get garbaged. The Erlang compiler&lt;br /&gt;recognises things like this and attempts to save space by storing N1 in the register used for N   (if this&lt;br /&gt;is possible).&lt;/p&gt;


	&lt;p&gt;This above code &lt;strong&gt;is&lt;/strong&gt; a loop (after compilation)&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;BTW&lt;/span&gt; We&amp;#8217;d really write the second clause of sum as:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;sum(N, Sum) -&amp;gt; sum(N-1, Sum+N)&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Without the temporary variables. The version I wrote was so you can see what happens to the variables.&lt;/p&gt;


	&lt;p&gt;Hope that helps!&lt;/p&gt;


	&lt;p&gt;/Joe&lt;/p&gt;</description>
      <pubDate>Tue, 26 Feb 2008 10:04:34 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:275:2330</guid>
      <author>Joe Armstrong</author>
      <link>http://forums.pragprog.com/forums/27/topics/275</link>
    </item>
    <item>
      <title>2.6 One time assigments posted by Alexey Kuznetsov @ Tue, 26 Feb 2008 08:14:52 -0000</title>
      <description>&lt;p&gt;I agree. And i see that style is a good style. But really i try to imagine situation that can totally brake that logic &amp;#8211; loops. If you try use loops in any languages you must reuse loop iterator all time. And that is a question &amp;#8211; how to solve that. There Joe explain new style, but don&amp;#8217;t explain main differents between languages.&lt;/p&gt;</description>
      <pubDate>Tue, 26 Feb 2008 08:14:52 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:275:2329</guid>
      <author>Alexey Kuznetsov</author>
      <link>http://forums.pragprog.com/forums/27/topics/275</link>
    </item>
    <item>
      <title>2.6 One time assigments posted by Alain O'Dea @ Tue, 26 Feb 2008 00:54:41 -0000</title>
      <description>&lt;p&gt;I think Joe was trying to get at a different kind of resetting of a variable. Think of Java.&lt;/p&gt;


&lt;pre&gt;String street = "1 Infinite Loop";
street = street.replace("1", "1A");
&lt;/pre&gt;

	&lt;p&gt;Erlang&amp;#8217;s variables are a lot like Java finals:&lt;br /&gt;&lt;pre&gt;final String street = "1 Infinite Loop";
final String correctedStreet = street.replace("1", "1A");
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;In Erlang:&lt;br /&gt;&lt;pre&gt;Street = "1 Infinite Loop",
{ok, CorrectedStreet, _} = regexp:sub(Street, "1", "1A").
&lt;/pre&gt;&lt;/p&gt;


	&lt;p&gt;The &amp;#8221;=&amp;#8221; operator in Erlang is not assignment although it may appear to be. It declares a constraint. It declares that the left hand and right hand sides are equal. By necessity everything on the right-hand side must be bound or set while the left-hand side may have unbound variables which will become bound to satisfy the constraint as declared.&lt;/p&gt;</description>
      <pubDate>Tue, 26 Feb 2008 00:54:41 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:275:2328</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/275</link>
    </item>
    <item>
      <title>2.6 One time assigments posted by Alexey Kuznetsov @ Mon, 25 Feb 2008 15:21:08 -0000</title>
      <description>&lt;p&gt;At end of 2.6 you can read bullet:&lt;/p&gt;


&lt;blockquote&gt;
	&lt;p&gt;At this point you might be wondering how it&#8217;s possible to program with- &lt;br /&gt;&amp;gt; out variables. How can you express something like X = X + 1 in Erlang? &lt;br /&gt;&amp;gt; The answer is easy. Invent a new variable whose name hasn&#8217;t been used &lt;br /&gt;&amp;gt; before (say X1), and write X1 = X + 1.&lt;/p&gt;

&lt;/blockquote&gt;




	&lt;p&gt;But my question is how it work for in for/next cycles. And &lt;span class="caps"&gt;IMHO&lt;/span&gt; right explanation is: recursion examples.&lt;/p&gt;</description>
      <pubDate>Mon, 25 Feb 2008 15:21:08 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:275:2325</guid>
      <author>Alexey Kuznetsov</author>
      <link>http://forums.pragprog.com/forums/27/topics/275</link>
    </item>
    <item>
      <title>erl rr? posted by Darcy Laycock @ Wed, 06 Feb 2008 11:27:44 -0000</title>
      <description>&lt;p&gt;Looks like your missing a closing } on the record declaration.&lt;/p&gt;</description>
      <pubDate>Wed, 06 Feb 2008 11:27:44 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:153:2263</guid>
      <author>Darcy Laycock</author>
      <link>http://forums.pragprog.com/forums/27/topics/153</link>
    </item>
    <item>
      <title>getting error on starting chat-client: lib_md5 missing? posted by Alain O'Dea @ Fri, 01 Feb 2008 01:56:31 -0000</title>
      <description>&lt;p&gt;lib_md5.erl:&lt;br /&gt;&lt;pre&gt;%% ---
%%  Excerpted from "Programming Erlang" 
%%  Copyrights apply to this code. It may not be used to create training material, 
%%  courses, books, articles, and the like. Contact us if you are in doubt.
%%  We make no guarantees that this code is fit for any purpose. 
%%  Visit &amp;lt;a href="http://www.pragmaticprogrammer.com/titles/jaerlang"&amp;gt;http://www.pragmaticprogrammer.com/titles/jaerlang&amp;lt;/a&amp;gt; for more book information.
%%---
-module(lib_md5).

%% modfied to use BIFs

-export([string/1, file/1, bin/1, binAsBin/1, digest2str/1]).

-define(BLOCKSIZE, 32768).
-define(IN(X,Min,Max), X &amp;gt;= Min, X =&amp;lt; Max).

%% md5:string(string())      -&amp;gt; BinDigest
%% md5:file(FileName)        -&amp;gt; {ok, BinDigest} | {error, E} 
%% md5:digest2str(BinDigest) -&amp;gt; StringDigest

%% md5:file works with chunks so should work correctly with extremely
%% large files

string(Str) -&amp;gt; digest2str(erlang:md5(Str)).

file(File) -&amp;gt;
    case file:open(File, [binary,raw,read]) of
    {ok, P} -&amp;gt; loop(P, erlang:md5_init());
    Error   -&amp;gt; Error
    end.

loop(P, C) -&amp;gt;
    case file:read(P, ?BLOCKSIZE) of
    {ok, Bin} -&amp;gt;
        loop(P, erlang:md5_update(C, Bin));
    eof -&amp;gt;
        file:close(P),
        {ok, erlang:md5_final(C)}
    end.

digest2str(Digest) -&amp;gt; bin2str(binary_to_list(Digest)).

bin2str([H|T]) -&amp;gt;
    {H1, H2} = byte2hex(H),
    [H1,H2|bin2str(T)];
bin2str([]) -&amp;gt;
    [].

byte2hex(X) -&amp;gt; 
    {nibble2hex(X bsr 4), nibble2hex(X band 15)}.

nibble2hex(X) when ?IN(X, 0, 9)   -&amp;gt; X + $0;
nibble2hex(X) when ?IN(X, 10, 15) -&amp;gt; X - 10 + $a.

%% compute the md5 checksum of a binary
bin(Bin) -&amp;gt;
    C1 = erlang:md5_init(),
    C2 = erlang:md5_update(C1, Bin),
    C3 = erlang:md5_final(C2),
    digest2str(C3).

binAsBin(Bin) -&amp;gt;
    C1 = erlang:md5_init(),
    C2 = erlang:md5_update(C1, Bin),
    erlang:md5_final(C2).&lt;/pre&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 01 Feb 2008 01:56:31 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:239:2250</guid>
      <author>Alain O'Dea</author>
      <link>http://forums.pragprog.com/forums/27/topics/239</link>
    </item>
    <item>
      <title>getting error on starting chat-client: lib_md5 missing? posted by wasiq hasan @ Mon, 28 Jan 2008 21:51:27 -0000</title>
      <description>&lt;p&gt;Hi, i am trying to execute chat clietn and geting the folowing error.&lt;br /&gt;iam running it on linux.i did not find lib_md5.erl inth ecode i downloaded.&lt;/p&gt;


	&lt;p&gt;what i ned to make it run? here is te eror&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;make chat_client&lt;br /&gt;mkdir -p /home/wasiq/.erlang_config/&lt;br /&gt;cp conf /home/wasiq/.erlang_config/lib_chan.conf&lt;br /&gt;make clean - clean up&lt;br /&gt;erl -pa ../ -s chat_client test&lt;br /&gt;Erlang (BEAM) emulator version 5.6 &lt;a&gt;source&lt;/a&gt; &lt;a href="hipe"&gt;async-threads:0&lt;/a&gt; [kernel-poll:false]&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;Eshell V5.6  (abort with ^G)&lt;br /&gt;1&amp;gt; chat_client disconnected unexpected:{&amp;#8216;EXIT&amp;#8217;,&amp;lt;0&gt;,normal}&lt;/p&gt;


	&lt;p&gt;=ERROR &lt;span class="caps"&gt;REPORT&lt;/span&gt;==== 28-Jan-2008::21:40:05 ===&lt;br /&gt;Error in process &amp;lt;0&gt; with exit value: {undef,[{lib_md5,string,[&amp;#8220;pzbaplovtpmhazjuvcpdyqishAsDT67aQ&amp;#8221;]},{lib_chan,authenticate,4},{lib_chan,connect,5},{chat_client,try_to_connect,4}]}&lt;/p&gt;


	&lt;p&gt;chat_client disconnected unexpected:{&amp;#8216;EXIT&amp;#8217;,&amp;lt;0&gt;,
                                     {undef,
                                      [{lib_md5,string,&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;{lib_chan,authenticate,4},
{lib_chan,connect,5},
{chat_client,try_to_connect,4}]}}&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;thanks&lt;br /&gt;wasiq&lt;/p&gt;</description>
      <pubDate>Mon, 28 Jan 2008 21:51:27 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:239:2230</guid>
      <author>wasiq hasan</author>
      <link>http://forums.pragprog.com/forums/27/topics/239</link>
    </item>
  </channel>
</rss>
