[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to repeat a scheme function that creates a Score
From: |
Jean Abou Samra |
Subject: |
Re: how to repeat a scheme function that creates a Score |
Date: |
Thu, 7 Apr 2022 08:51:10 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 |
Le 07/04/2022 à 07:55, Jeff Olson a écrit :
On 4/6/2022 12:35 AM, Jean Abou Samra wrote:
The attached MWE file has lots of my failed attempts commented out
(I'm at a teachable moment if someone has a moment to teach). Or
just point me to the right manual page(s).
Here is a piece of code that works:
$@(map (lambda (i) (scr)) (iota 10))
Now let's go through your attempt to see why they are failing.
This is an amazing user group! Thank you times three to Aaron,
Valentin and Jean for your immediate and expert responses!
And special thanks to you, Jean, for giving me a full course
explaining why all my previous attempts had failed. That was a very
valuable learning experience!
The code I'm using now is:
%%%%
% scors generates a specified number of scores
% e.g. invoke $@(scors 10) from lilypond to generate ten scores
#(define (scors num) (map (lambda (i) (scr)) (iota num)))
%%%%
This works nicely as I can make a series of invocations in different
bookparts (simulating separate chapters) while preserving the overall
sequence of piece numbers.
I'd like you to check my learning on "$@" ...
Per the ER section 1.2.1, "There are also ‘list splicing’ operators
|$@| and |#@| that insert all elements of a list in the surrounding
context."
So it's not part of scheme but part of lilypond, as a bridge between
scheme and lilypond.
Yes.
And that it tells lilypond to preserve all the elements of scheme list
value as a sequence of expressions/values to be parsed/interpreted by
lilypond, as opposed to getting just the value of the last element of
the list.
Not the last element of the list, but the list itself. If you do
myVariable = #(list ...), it assigns a list value to myVariable.
Assuming the list we're talking about is #(list a b), referencing
it with #x gives you #(list a b), whereas #@x is (modulo subtle
parsing details I think) equivalent to #a #b.
And so it is analogous (at least mnemonically) to the meaning of "$%"
in bash (if I remember correctly), which preserves a sequence of
command line arguments as separate values rather than combining them
as one argument.
I think you mean '$@', but it's kind of the same thing, yes.
But may I ask, why are "$@" and "#@" called 'list splicing'
operators? The same terminology is used in Perl for what appears to
me to be very different behaviors (list editing, insertion and
removal), so I'd appreciate learning why 'splicing' is considered
descriptive in lilypond.
Well, it's about the same, isn't it? As far as I can read from
Perl tutorials, list splicing allows you to insert all elements
from a list to replace some sequence in another list. For LilyPond,
the inspiration is not Perl but rather Scheme (of course), which
has an unquote-splicing operator, shortened as ",@" (hence the
spellings "#@" and "$@").
scheme@(guile-user)> (define lst '(1 2 3))
scheme@(guile-user)> `(a b ,lst c)
$1 = (a b (1 2 3) c)
scheme@(guile-user)> `(a b ,@lst c)
$2 = (a b 1 2 3 c)
The role of ",@" is to insert all elements from its argument
into the surrounding list. That's quite similar to what "#@"
and "$@" do.
Best,
Jean