[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme question: symbol to music
From: |
Carl Sorensen |
Subject: |
Re: Scheme question: symbol to music |
Date: |
Wed, 12 Nov 2008 04:48:59 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
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.
>
You need to use the procedure primitive-eval to evaluate a symbol
(if (defined? sym)
(primitive-eval sym)
(make-music 'SequentialMusic 'void #t))
should do the trick.
Here's some test code that worked for me:
%%% Start of test code
\version "2.11.64"
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)))
myNotes = \relative c' { f4 g a b }
{
\ifDefined #'myNotes
\ifDefined #'undefinedNotes
}
%%% End of test code
HTH,
Carl
- Scheme question: symbol to music, Johan Vromans, 2008/11/11
- Re: Scheme question: symbol to music,
Carl Sorensen <=
- Re: Scheme question: symbol to music, Mark Polesky, 2008/11/12
- Re: Scheme question: symbol to music, Johan Vromans, 2008/11/12
- Re: Scheme question: symbol to music, Johan Vromans, 2008/11/12
- Re: Scheme question: symbol to music, Graham Percival, 2008/11/12
- Re: Scheme question: symbol to music, Johan Vromans, 2008/11/12
- Re: Scheme question: symbol to music, Graham Percival, 2008/11/12
- Re: Scheme question: symbol to music, Johan Vromans, 2008/11/13