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

黃耀賢 (Yau-Hsien Huang) g9414002.pccu.edu.tw@REDACTED
Mon Jul 23 17:48:08 CEST 2018


Though the RHS of andalso is not typed in Erlang.

On Mon, Jul 23, 2018 at 10:35 PM, Richard O'Keefe <raoknz@REDACTED> wrote:

> No, that is *not* why andalso/2 was added to the language.
> The very spelling of the token, 'andalso', was copied from
> a language, Standard ML, which is strictly typed and does
> not allow <test> andalso <action>.
>
> On 23 July 2018 at 23:25, 黃耀賢 (Yau-Hsien Huang) <
> g9414002.pccu.edu.tw@REDACTED> wrote:
>
>> 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.
>>
>>
>> _______________________________________________
>> 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/6e219275/attachment.htm>


More information about the erlang-questions mailing list