Scheme function problems

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Scheme function problems

Kieren MacMillan
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

Thanks!
Kieren.


_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme function problems

Jan Nieuwenhuizen
Kieren Richard MacMillan writes:

> Hello, all --
>
> Can anyone tell me why the code
>
> returns
>
> ERROR: Wrong type (expecting real number): lilyvartmpa

$padding is used inside a quoted list, but it should be unquoted.  Try

    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 { c' c' } c' }

The error message is horrible; programmers who implement constant
error messages should consider a career switch.

Jan.

--
Jan Nieuwenhuizen <[hidden email]> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien       | http://www.lilypond.org


_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme function problems

Nicolas Sceaux
In reply to this post by Kieren MacMillan
Kieren Richard MacMillan <[hidden email]> 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


_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme function problems

Kieren MacMillan
In reply to this post by Jan Nieuwenhuizen
Hi, Jan:

Thanks! Your code works great...

One more question -- I want to compensate, but neither

     \once \override Score.BarLine #'space-alist =
     #`((first-note extra-space . ,$padding) (right-edge extra-
space . -,$padding))

nor

     \once \override Score.BarLine #'space-alist =
     #`((first-note extra-space . ,$padding) (right-edge extra-
space . (* -1 ,$padding ) ))

works correctly. In other words, I'm not sure how to encode a  
negative variable.

On a related note, what's the best Scheme tutorial on-line? Nothing I  
could find -- on lilypond or elsewhere -- was apparently good enough  
to answer this question for me...  ;-)

Thanks,
Kieren.


_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Scheme function problems

Nicolas Sceaux
Kieren Richard MacMillan <[hidden email]> writes:

> Hi, Jan:
>
> Thanks! Your code works great...
>
> One more question -- I want to compensate, but neither
>
>      \once \override Score.BarLine #'space-alist =
>      #`((first-note extra-space . ,$padding) (right-edge extra-
> space . -,$padding))

this is internally changed to:

#`((first-note extra-space . ,lilyvartmpa)
   (right-edge extra-space . -,$padding))

-,$padding is just a strange symbol name.

> nor
>
>      \once \override Score.BarLine #'space-alist =
>      #`((first-note extra-space . ,$padding) (right-edge extra-
> space . (* -1 ,$padding ) ))

This is changed to:

#`((first-note extra-space . ,lilyvartmpa)
   (right-edge extra-space . (* -1 ,lilyvartmpa)))

which value would be (with 3.0 padding):

((first-note extra-space . 3.0)
 (right-edge extra-space . (* -1 3.0)))

That is, the right edge extra space value is not a number, but a list,
containing the procedure * and the numbers -1 and 3.0.

Use:

#`((first-note extra-space . ,$padding)
   (right-edge extra-space . ,(* -1 $padding)))

or

#`((first-note extra-space . ,$padding)
   (right-edge extra-space . ,(- $padding)))


_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user