Hm. The Erlang people talk of "Pattern matching in function head and in case and receive clauses are optimized by the compiler." & "the compiler is free to rearrange the clauses. It will generate code similar to this".
Of course it's optimized. Like you would expect from a language where the only way to loop is recursion.

Yet, this works in Erlang:

f(1) -> io:format("I got one!"); f(X) when X rem 2 == 0 -> io:format("I got even!"); f(X) when X rem 2 == 1 -> io:format("I got odd! (but not one)"). ... f(random:uniform(1000)). f("Now eat this!"). %% runtime error
Just for comparison (with Perls):
-module(fns). -export([run_test/0]). f(X, Acc) when X rem 2 == 0 -> Acc; f(X, Acc) when X rem 2 == 1 -> Acc + 1. run_test() -> TSeq = [random:uniform(10) || _ <- lists:seq(1, 1000000)], {Time, Result} = timer:tc(fun() -> lists:foldl(fun f/2, 0, TSeq) end), io:format("~w microseconds~nResult: ~w~n", [Time, Result]).
output:
93267 microseconds Result: 500464
So, functions that actually do something in Erlang (count odd numbers) are three times faster then Perls functions that do nothing whatsoever.

In reply to Re^9: rough approximation to pattern matching using local (Multi Subs) by Anonymous Monk
in thread rough approximation to pattern matching using local by gregory-nisbet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.