lilypond-user
[Top][All Lists]
Advanced

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

Re: music functions: how to translate "user-durations" in ly:durations


From: Nicolas Sceaux
Subject: Re: music functions: how to translate "user-durations" in ly:durations
Date: Sat, 17 Jun 2006 10:35:02 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin)

Michael Meixner <address@hidden> writes:

> One more question for my education (certainly not the last...):
>
> In this part:
> ==
> (for-each (lambda (event) ...)
> ==
> I tried "map" instead of "for-each" which yielded the same result.
>
> In "teach yourself Scheme" they say:
> "The 'for-each' procedure also applies a procedure to each element
> in a list, but returns void. The procedure application is done
> purely for any sied-effects it may cause."
>
> I don't get this, even the example provided doesn't enlighten me.
> What is the advantage of "for-each" in our case?
>
>               (define (setDuration event-chord)
>                       (for-each (lambda (event)
>                       (if (not (null? (ly:music-property event 'duration)))
>                                       (set! (ly:music-property event 
> 'duration) newDuration )))
>                               (ly:music-property event-chord 'elements))
>               event-chord)

Using for-each instead of map, you put the stress on the fact that the
function you're mapping is doing some side effect (here, setting a
property of the mapped objects), and that its result (the value the
function returns) is not important. Thus, the reader does not try to
mentaly grok what the result of the mapping is, s-he can just read the
body of the procedure to understand the whole.

[digression]
Using a loop construct (not part of guile), that would be:

  (loop for event in (ly:music-property event-chord 'elements)
        unless (null? (ly:music-property event 'duration))
        do (set! (ly:music-property event 'duration)
                 new-duration))

Some parts of the LilyPond scheme code would be easier to read (and to
write) if they'd use it, imho.




reply via email to

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