[erlang-questions] Keyword documentation

tsuraan tsuraan@REDACTED
Fri Feb 19 20:23:56 CET 2010


> Most common uses I've found are in list comprehensions:
>
> [ X || X <- List,  begin FooVal = foo(X), ... complex test using
> FooVal more than once ... end ].
>
> [ begin
>         FooVal = foo(X),
>         ... complex expression using FooVal more than once ...
>    end || X <- List ].
>
>
>
> It lets you introduce temporary variables in places where the context
> makes it difficult to reference them.
> I do this for documentation purposes sometimes (see R.O.K.s previous
> objection to F local fun var), and when a call to an expensive
> function needs to occur more than once in a decision process.
>
>
> Also works in binary comprehensions:
>
> <<  << X >> ||  << X >> <= Binary,  begin FooVal = foo(X), ... end >>.
>
> <<  <<(begin FooVal = foo(X), ... end)>> || << X >> <= Binary >>.
>
> The parens are necessary because the expression in the binary
> constructor has to be evaluated and returned as a valid element
> before the binary construction can occur.

That's some crazy stuff.  I never would have thought of doing that,
but now that I've seen it...  Thanks a ton!


More information about the erlang-questions mailing list