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

黃耀賢 (Yau-Hsien Huang) g9414002.pccu.edu.tw@REDACTED
Mon Jul 23 19:41:15 CEST 2018


I'm not interested in so-called "it's for something but the other." By
typing some code in both shell, I got an error message in SML/NJ when
typing the following code,

> true andalso nil;

though I got similar code working smoothly in Erlang when typing the
following code,

> is_list(true andalso []). %% The shell reported `true`.

So, what's the meaning of "being copied into?" Is it rigid that you borrow
a word from a language and keep all the nature of it? I don't think so.



On Tue, Jul 24, 2018 at 12:58 AM, Richard O'Keefe <raoknz@REDACTED> wrote:

> Yes, I know the RHS of 'andalso' is not typed in Erlang.
> So what?  The point is that when 'andalso' and 'orelse'
> were copied into Erlang from Standard ML, they did not
> drag the obsolete baggage of being ersatzes for WHEN and
> UNLESS in with them.  They were added to provide
> non-strict AND and OR for Boolean expressions, and that
> is all they were added for, just as 'and' and 'or' were
> added to provide strict AND and OR.
>
> They were not added to provide a cryptic way to obfuscate
> conditionals you could already easily write.
>
>
>
> On 24 July 2018 at 03:48, 黃耀賢 (Yau-Hsien Huang) <
> g9414002.pccu.edu.tw@REDACTED> wrote:
>
>> 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.
>>
>>
>> _______________________________________________
>> 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/20180724/083752d2/attachment.htm>


More information about the erlang-questions mailing list