[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme function problems
From: |
Nicolas Sceaux |
Subject: |
Re: Scheme function problems |
Date: |
Sat, 15 Apr 2006 11:23:44 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) |
Kieren Richard MacMillan <address@hidden> writes:
> Hello, all --
>
> Can anyone tell me why the code
>
> \version "2.8.1"
> barpadding = #(define-music-function (parser location padding music)
> (number? ly:music?)
> #{
> \once \override Score.BarLine #'space-alist =
> #'((first-note extra-
> space . $padding))
> $music
> #}
> )
> { c'1 \barpadding #32.0 { c' c' } c' }
>
> returns
>
> ERROR: Wrong type (expecting real number): lilyvartmpa
The reason of the error is the following:
When using a $variable inside scheme context in a #{ #} expression, the
"$padding" is replaced by a symbol (of the form
lilyvartmpNNN), which is bound to value given to padding. That is,
this is equivalent to:
#(define lilyvartmpa <value of padding>)
{
\once \override Score.BarLine #'space-alist =
#'((first-note extra-space . lilyvartmpa))
{..music..}
}
'((first-note extra-space . lilyvartmpa)) is a quoted, literal list, and
when these data are used, a symbol 'lilyvartmpa is found where a number
is expected, hence the cryptic message.
Don't use a quoted list where you want to introduce a variable. You can
build the list by calling list, cons, etc, or use the dedicated feature:
backquote.
#`((first-note extra-space . ,lilyvartmpa))
is like writing:
#(list (cons 'first-note (cons 'extra-space lilyvartmpa)))
where lilyvartmpa will be evaluated.
So, as Jan explained, a solution is:
#`((first-note extra-space . ,$padding))
^
|
a backquote, not a quote.
nicolas