[Top][All Lists]

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

Re: music-functions: #$var1 or just $var1 ?

From: Carl Sorensen
Subject: Re: music-functions: #$var1 or just $var1 ?
Date: Sun, 25 Apr 2010 20:06:33 -0600

On 4/25/10 11:51 AM, "Mark Polesky" <address@hidden> wrote:

> Nicolas Sceaux wrote:
>> Inside the #{ ... #} construct, you have to use #$variable
>> where a scheme token is required, but you use $variable
>> where \variable could be used.  Behind the scenes,
>> $variable is actually replaced by something like \tmpvar
>> before being parsed.
> Can you provide an example of a case where #$ is required
> within #{ #} ?  I can't find one.  $ seems to always work.

As I understand it, in LilyPond input, the # is a token that indicates a
Scheme expression follows.

In a #{ #} expression, $ is a token that indicates a Scheme expression to be
evaluated follows.

I don't think that #$ is ever required inside of #{ #}.

And there are some places where we use # that it is not strictly required,
i.e. where the argument needs to be a string, and it can be either a
LilyPond string (no #) or a Scheme string (start with a #).

We made a decision a number of years ago to always put # in if it was
accepted, even when it wasn't required, in order to be more consistent.

Similarly, we made a decision to put { after \new Staff, even if it wasn't
required, for consistency.  So we do

\new Staff {
  \new Voice {
       c d e f

even though

\new Staff \new Voice {
  c d e f

would also work.

In my opinion, we should not request that the user use #$, but we should
just indicate that inside a #{ #} block $ is used to indicate a Scheme
expression to be evaluated.

> In fact, I'm probably missing something obvious, but I'm
> unable even to find a case where a scheme token (with #) is
> actually required in a regular music block.  I've found I
> can even do such bizarre things as this:
>   voiceCtx = Voice
>   noteGrob = NoteHead
>   colorSym = #'color
>   redVal = #red
>   { \override \voiceCtx.\noteGrob \colorSym = \redVal c'' }
> and by extension, I can also do this (without using `#$'):
>   overrideAlias =
>   #(define-music-function
>     (parser location ctx grob prop-sym prop-val)
>     (scheme? scheme? scheme? scheme?)
>     #{
>       \override $ctx . $grob $prop-sym = $prop-val
>     #})
>   { \overrideAlias Voice NoteHead #'color #red c'' }
> So, two things:
> 1) what is a case where omitting the # causes an error?

I doubt there is one -- see above.

> 2) what is the danger of omitting the # otherwise?

I don't think there is any.


reply via email to

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