lilypond-user
[Top][All Lists]
Advanced

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

Re: Validating a Scheme list


From: David Kastrup
Subject: Re: Validating a Scheme list
Date: Thu, 15 May 2014 10:26:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

Urs Liska <address@hidden> writes:

> Hi all,
>
> I am working on a Scheme function and would like to check if I have found the 
> best solution for a specific subpart. Somehow it looks more complicated than 
> necessary.
>
> The function needs to test if each element of a given list is a (sub)list 
> with exactly two elements. So
>
> '((1 2)(3 4))
>
> would return #t while
>
> '((5 6)(7 8 9))
>
> would return #f.
>
> My solution is
>
> \version "2.19.6"
>
> validate =
>
> #(define-scheme-function (parser location lst) (list?)
>
>    (if (memv #f (map (lambda sig

Why (lambda sig ... rather than (lambda (sig) ... here and consequently
(car sig) instead of sig below?

>                        (and (list? (car sig))
>
>                             (= 2 (length (car sig))))) lst))
>
>        (display "invalid")
>
>        (display "valid"))
>
>    (newline))

(if (every (lambda (sig) (eqv 2 (length+ sig))) lst)
    (display "valid")
    (display "invalid"))

-- 
David Kastrup



reply via email to

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