lilypond-user
[Top][All Lists]
Advanced

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

Re: Scheme question: symbol to music


From: Nicolas Sceaux
Subject: Re: Scheme question: symbol to music
Date: Wed, 12 Nov 2008 20:38:03 +0100

Le 12 nov. 08 à 05:48, Carl Sorensen a écrit :

Johan Vromans <jvromans <at> squirrel.nl> writes:


Stupic question, I assume...

In a scheme function I have a symbol that is the name of a lilypond
expression. How can I get its music value?

E.g.

 ifDefined =
 #(define-music-function
  (parser location sym)
  (symbol?)

  (if (defined? sym)
      ??? return the value of the expression ???
   (make-music 'SequentialMusic 'void #t)))

So I can write:

 \ifDefined #'myNotes

and have it expand to myNotes (if defined), or a void music expression
otherwise.


ifDefined =
 #(define-music-function (parser location sym) (symbol?)
     " Return the music if @code{sym} is defined, and void if not"
     (if (defined? sym)
         (primitive-eval sym)
         (make-music 'SequentialMusic 'void #t)))


A more idiomatic way to do it:

ifDefined =
#(define-music-function (parser location sym) (symbol?)
   (let ((music (ly:parser-lookup parser sym)))
     (if (ly:music? music)
         music
         (make-music 'Music 'void #t))))

nicolas





reply via email to

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