lilypond-user
[Top][All Lists]
Advanced

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

Re: for-each?


From: Valentin Petzel
Subject: Re: for-each?
Date: Sun, 02 Jul 2023 21:26:50 +0200

Hello Pierre,

you should not use for-each in such a case. for-each is essentially a version 
of map that does not return anything. So

(for-each (lambda (part) part) parts)

does not give you any return, and

(map (lambda (part) part) parts)

would not change anything (it instructs to map the identity onto a list). 
Rather you problem is that you want to include a list of different music 
expression. For this you’ve got two approaches:

The first is to use the @ token to tell the parser to insert not the scheme 
object in question, but all the elements of it:

group =
#(define-music-function
  (parts) (list?)
  #{\new StaffGroup <<
    #@parts
  >>#})

The other way would be to construct the SimultaneousMusic << ... >> directly 
in scheme:

group =
#(define-music-function
  (parts) (list?)
  #{
    \new StaffGroup
    $(make-music 'SimultaneousMusic 'elements parts)
  #})

Cheers,
Valentin

Am Sonntag, 2. Juli 2023, 21:05:21 CEST schrieb Pierre-Luc Gauthier:
> How can I go about using for-each in this example for the group function to
> accept an arbitrary number of parts ?
> 
> \version "2.25.7"
> 
> parts = #(list
>           #{ {c'} #}
>           #{ {d'} #}
>           #{ {e'} #}
>           #{ {f'} #} )
> 
> group =
> #(define-music-function
>   (parts) (list?)
>   #{\new StaffGroup <<
>     %#(for-each (lambda (part) part) parts)
>     #(car parts)
>     #(car (cdr parts))
>     #(car (cdr (cdr parts)))
>     #(car (cdr (cdr (cdr parts))))
> 
>   >>#})
> 
> \group \parts

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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