lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: procedure to check equality of list-elements


From: Jean Abou Samra
Subject: Re: procedure to check equality of list-elements
Date: Sun, 6 Nov 2022 16:17:43 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1

Le 06/11/2022 à 16:13, Luca Fascione a écrit :
Note the detail that + a b c and eq? a b c don't do the exact same thing:

+ a b c is equivalent to (a + b) + c
eq? a b c is equivalent to (a == b) && (b == c)


Yes. On the other hand, Scheme (+ a b c d) behaves like Python a+b+c+d, and Scheme (equal? a b c d) behaves (I mean, not on details like how things are actually compared, but logically) like Python a == b == c == d (whereas in C/C++ the expression a == b == c == d  is evaluated as (((a == b) == c) == d).


The list form has short circuiting if I remember right (eq? bails out on the first false it finds), but I don't remember how evaluation works for the arguments, in terms of what side effects are meant to observable when early-out happens

eq?, eqv? and equal? are procedures (= functions). Therefore, Scheme not being a lazy language, all inner arguments are first evaluated and any side effects are observable. On the other hand, "and" and "or" are macros, with lazy behavior.

Best,
Jean


Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]