[erlang-questions] case expression scope

Tony Rogvall <>
Wed Mar 5 00:23:12 CET 2014


Of course. use list comprehensions! or?

This is kind of fun. Check the generated beam code for this module (using R16B02 right now)

-module(compcase).
-compile(export_all).
-compile(inline).
-compile({inline_size, 100}).
-compile({inline_unroll, 2}).

f(X,Y) ->
    [A] = [case {X,Y} of 
	       {0,Q} -> Q; 
	       {P,Q} -> P+Q 
	   end || _ <- [[]]],
    [B] = [case {X,Y} of 
	       {0,Q} -> Q; 
	       {P,Q} -> P*Q 
	   end || _ <- [[]]],
    {A,B}.


g(X,Y) ->
    A = fun({0,Q}) -> Q; 
	    ({P,Q}) -> P+Q 
	 end({X,Y}),
    B = fun({0,Q}) -> Q; 
	   ({P,Q}) -> P*Q
	end({X,Y}),
    {A,B}.




On 4 mar 2014, at 23:27, Anthony Ramine <> wrote:

> Note that there is also one scope per generator input, which does not spill into the generator pattern nor the rest of the comprehension.
> 
> -- 
> Anthony Ramine
> 
> Le 4 mars 2014 à 22:49, Richard A. O'Keefe <> a écrit :
> 
>> 	- a list comprehension is a scope
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140305/da5ecbc2/attachment.html>


More information about the erlang-questions mailing list