[erlang-questions] erlang sucks

Sean Hinde sean.hinde@REDACTED
Wed Mar 12 19:31:22 CET 2008


This line will indeed never match :-) Well spotted

Sean

On 12 Mar 2008, at 17:48, David Mercer wrote:

> Perhaps I am misunderstanding the comma or == operator, but for what  
> values
> of X will the following guard evaluate to true?
>
> 	when X == '123', X == '456'
>
> Please advise.  Thank-you.
>
> DBM
>
> -----Original Message-----
> From: erlang-questions-bounces@REDACTED
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Sean Hinde
> Sent: Tuesday, March 11, 2008 15:06
> To: Mats Cronqvist
> Cc: Erlang mailing list
> Subject: Re: [erlang-questions] erlang sucks
>
>
> On 11 Mar 2008, at 19:26, Mats Cronqvist wrote:
>
>> Sean Hinde wrote:
>>>
>>> On 11 Mar 2008, at 12:47, Mats Cronqvist wrote:
>>>
>>>>
>>>> * 'if' is  completely worthless, and should ideally be obsoleted.
>>>
>>> No, no no! I like 'if' It allows some neat constructs that are
>>> horrible with case.
>>
>> i was afraid no one was going to bite... still, I'd like an example
>> or 2.
>
> I'm thinking of things like:
>
> case X of
> 	_ when X == abc; X == xyz ->
> 		do_abc_or_xyz();
>         _ when X == '123', X == '456' ->
> 		do_123456()
> 	'123' ->
> 		do_123_only();
>         fred ->
>                 do_fred()
> end
>
> vs
>
> if
> 	X == abc;
> 	X == xyz ->
> 		do_abc_or_xyz();
>         X == '123',
> 	X == '456' ->
> 		do_123456();
> 	X == '123' ->
> 		do_123_only();
>         X == fred ->
>                 do_fred()
> end
>
> I don't much like the _ when business.
>
> 'if' is also useful when you want to branch on a bunch of unrelated
> boolean variables in various combinations:
>
> case {X,Y,Z} of
> 	{true, false, _} ->
> 		do_a();
>         {false, _, true} ->
> 		do_b();
> 	_ ->
> 		do_c()
> end
>
> vs
>
> if
> 	X and not Y ->
>             do_a;
> 	not X and Z ->
>             do_b;
> 	true ->
>             do_c
>     end.
>
> I find the second more clearly states the intent. You also don't have
> to remember the positions in the tuple to parse the code (though you
> do need to know that 'not' is stickier* than 'and')
>
> Sean
>
> * IANACS
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list