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: Thomas Morley
Subject: Re: procedure to check equality of list-elements
Date: Sun, 6 Nov 2022 13:27:46 +0100

Am So., 6. Nov. 2022 um 13:07 Uhr schrieb Jean Abou Samra <jean@abou-samra.fr>:
>
> Le 06/11/2022 à 13:03, Thomas Morley a écrit :
> > Hi,
> >
> > in !1701 `ly:beam::calc-knee' checks whether all list-elements are equal.
> > Basically doing (apply eqv? <number-list>).
> > Tbh, I don't understand why it works...
>
>
> eqv? has no problem working on more than two elements.
>
> scheme@(guile-user)> (eqv? 1 1)
> $1 = #t
> scheme@(guile-user)> (eqv? 1 2)
> $2 = #f
> scheme@(guile-user)> (eqv? 1 1 1)
> $3 = #t
> scheme@(guile-user)> (eqv? 1 1 2)
> $4 = #f
> scheme@(guile-user)> (eqv? 1 1 1 1)
> $5 = #t
> scheme@(guile-user)> (eqv? 1 2 3 4)
> $6 = #f
> scheme@(guile-user)> (eqv?)
> $7 = #t
>

Call me surprised.
The guile manual only gives code-examples comparing _two_ values with
eq? and friends.
I didn't know and didn't imagine it would work for more arguments as
you wrote above.

>
>
> This is similar to how in other languages you have to
> repeat the + operator (a+b+c+d) whereas in Scheme you
> can do (+ a b c d).
>
>
>
> > Though, the need to check a list for all list-elements are equal
> > happened to me not only once.
> > Thus, would it be acceptable to add something like:
> >
> > (define* (equal-list-elts? list #:optional (proc eq?))
> >    (apply proc list))
> >
> > to lily-library.scm?
>
>
>
> What would be the point? Do you dislike (apply proc lst)?
>
Ofcourse not, though you need to know that the chosen proc is suitable
for the task.
For me eqv? was always meant to work with exactly two values, like cons.
But (apply cons '(1 2 3)) fails ofcourse.

In the past I searched the guile-manual and our own lilbrary to get a
procedure testing equality of list-elements. To no avail. So I ended
up defining some custom-recursion...
Having a named (and documented) procedure would probably have helped.

Cheers,
  Harm



reply via email to

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