[erlang-questions] Orelse and andalso as short-hand for case

黃耀賢 (Yau-Hsien Huang) g9414002.pccu.edu.tw@REDACTED
Mon Jul 23 13:25:55 CEST 2018


IMO, it's meaningful.

Think that,

Msg /= nil and io:fwrite("blah, blah, ...~n"). %% It won't build a boolean
expression.

But

Msg /= nil andalso io:fwrite("blah, blah, ...~n"). %% Confirm the Msg is
nothing and also say "blah, blah, ..."

I think the reason why andalso/2 was built. Though, andalso/2 won't be used
for a general default value usage like what we saw in JS or Perl, because
the first argument of andalso/2 must be either true or false.



On Mon, Jul 23, 2018 at 7:05 PM, Jesper Louis Andersen <
jesper.louis.andersen@REDACTED> wrote:

> On Sun, Jul 22, 2018 at 9:09 PM Jachym Holecek <freza@REDACTED>
> wrote:
>
>> # Viktor Söderqvist 2018-07-22:
>> >
>> >     Msg /= undefined andalso io:format("Message: ~s~n", [Msg]),
>> >
>> > I this good or bad style?
>>
>> It is horrible style. Pain to read, pain to modify, pain to reason about.
>>
>> Simple clear question deserves a simple clear answer. :-)
>>
>>
> ​I don't like the style either, mostly because it messes with the types.
> andalso and orelse expects boolean expressions, but the style used breaks
> that format. However, something like
>
> [x || Msg /= undefined]
>
> doesn't.​
>
>
> --
> J.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 

Best Regards.

--- Y-H. H.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180723/e53d937d/attachment.htm>


More information about the erlang-questions mailing list