[erlang-questions] style question - best way to test multiple non-guard conditions sequentially

Richard Carlsson <>
Mon Dec 16 11:32:52 CET 2013


On 2013-12-15 19:07 , Anthony Ramine wrote:
> Hello,
>
> I’ve thought about this again and realised that there is a technical reason not to expand cond expressions to nested cases directly. That reason is scoping rules.
>
> Let’s assume we compile this expression naively to nested cases:
>
> 	cond X = false -> X;
> 	     X = true -> X
> 	end
>
> =>
>
> 	case X = false of
> 	    true -> X;
> 	    false ->
> 	        case X = true of
> 	            true -> X;
> 	        end
> 	end.
>
> I would be *extremely* surprised that such an expression would crash with badmatch instead of returning true as it should.
>
> Regards,
>

Yes, these complications are the reasons why cond never got implemented 
beyond experimenting with the expansion you showed above. It needs 
clearly specified scoping rules, and support in all tools above the Core 
Erlang level. And nobody seemed to have the time to do that.

    /Richard




More information about the erlang-questions mailing list