[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: for-each?
From: |
David Kastrup |
Subject: |
Re: for-each? |
Date: |
Mon, 03 Jul 2023 00:28:56 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Jean Abou Samra <jean@abou-samra.fr> writes:
> Le dimanche 02 juillet 2023 à 15:05 -0400, Pierre-Luc Gauthier a écrit :
>
>> How can I go about using for-each in this example for the group function to
>> accept an arbitrary number of parts ?
>
>
> You can't — for-each is not the right tool for this. for-each is a purely
> imperative tool: it runs the same operation on each element of a list, and
> discards the result. What you actually want is called list splicing:
>
>
> ```
> \version "2.25.6"
>
> parts = #(list
> #{ {c'} #}
> #{ {d'} #}
> #{ {e'} #}
> #{ {f'} #} )
>
> group =
> #(define-music-function
> (parts) (list?)
> #{\new StaffGroup << #@parts >>#})
>
> \group \parts
> ```
That has an awkward look. I'd rather use
```
\version "2.25.6"
parts = {
{c'}
{d'}
{e'}
{f'}
}
group =
#(define-music-function
(parts) (ly:music?)
#{\new StaffGroup << #@(ly:music-property parts 'elements) >>#})
\group \parts
```
--
David Kastrup
- for-each?, Pierre-Luc Gauthier, 2023/07/02
- Re: for-each?, Valentin Petzel, 2023/07/02
- Re: for-each?, Jean Abou Samra, 2023/07/02
- Re: for-each?,
David Kastrup <=
- Re: for-each?, Pierre-Luc Gauthier, 2023/07/03
- Re: for-each?, Lukas-Fabian Moser, 2023/07/03
- Re: for-each?, David Kastrup, 2023/07/03
- Re: for-each?, David Kastrup, 2023/07/03
- Re: for-each?, Jean Abou Samra, 2023/07/03
- Re: for-each?, David Kastrup, 2023/07/03