lilypond-devel
[Top][All Lists]
Advanced

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

Nested quasiquoting and Scheme embedded in #{ #}


From: Jean Abou Samra
Subject: Nested quasiquoting and Scheme embedded in #{ #}
Date: Wed, 10 Aug 2022 13:32:41 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0

Hi,

A little request for feedback from Scheme power users:

Consider the following snippet from David K.

\version "2.23.11"

#(define-macro (pattern args result)
   `(define-music-function (parser location ,@args) ,(make-list (length args) 'ly:music?)
      #{ $@(list ,@result) #}))

$(pattern (A B C D) (A B D A C D)) { a' a' a' a' } { b' b' b' b' } { c'' c'' c'' c'' } { d'' d'' d'' d'' }


I was astounded that this works, but it does work. When you
quasiquote a S-expression containing embedded LilyPond #{ ... #},
and include a Scheme expression #... inside this, and use an unquote
inside that nested Scheme expression, it really gets substituted.

In the discussion
https://gitlab.com/lilypond/lilypond/-/merge_requests/1510#note_1056034206
we (developers) are considering a change in the implementation of
#{ ... #} that would have benefits, but it would not work with this sort
of case. One would have to use plain Scheme here, replacing

#{ $@(list ,@result) #}

with

(make-sequential-music (list ,@result))


The benefits of the change would be making the parsing more robust for
situations like a # in a LilyPond % comment within #{ ... #}, which should
not be interpreted as a Scheme expression.  It would also simplify the
implementation.

Note that you can't really do something useful with a quoted #{ ... #}
apart from evaluating it, so this use case is specific to macro contexts.

I believe it's OK calling this a very special case and no longer
supporting it, but I'd like to be sure. Would you have thought of
doing something like this? Would you have expected it to work?


Thanks,
Jean




reply via email to

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