lilypond-user
[Top][All Lists]
Advanced

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

Re: define-markup-function problem


From: Carl D. Sorensen
Subject: Re: define-markup-function problem
Date: Thu, 29 Jan 2009 21:30:42 -0700



On 1/29/09 1:56 PM, "Nicolas Sceaux" <address@hidden> wrote:

> 
> 
> Le 29 janv. 09 à 16:29, Carl D. Sorensen a écrit :
> 
>> 
>> 
>> 
>> On 1/29/09 7:12 AM, "Kieren MacMillan" <address@hidden>
>> wrote:
>> 
>>> Hi Carl,
>>> 
>>> So we have the following, which all work:
>>> 
>>> #(define-markup-command (test layout props stringA stringB) (string?
>>> string?)
>>>     (interpret-markup layout props
>>>         (markup (#:column (stringA stringB)))))
>>> 
>>> #(define-markup-command (test layout props stringA stringB) (string?
>>> string?)
>>>     (interpret-markup layout props
>>>     (markup #:column (cons stringA stringB))))
>>> 
>>> #(define-markup-command (test layout props stringA stringB) (string?
>>> string?)
>>> (interpret-markup layout props
>>> (markup (make-column-markup (list stringA stringB)))))
>>> 
>>> Which is "better code", and why?
>>> 
>> I prefer #3.  My reasons?
>> 
>> I don't like option 1, because this is a scheme function.  The use of
>> #:column as a scheme function is not standard -- it's mixing
>> LilyPond and
>> scheme.  Also, in scheme, you can't do (stringA stringB).  So
>> somehow the
>> #:column is triggering a macro that turns what would be illegal
>> scheme into
>> legal scheme.  I haven't spent the time to follow through exactly how.
> 
> No.

I definitely agree with you.


> 
> `markup' here is a macro. Think about it as a compiler. It takes some
> data, and generate some code. If you want to see what it exactly does,
> use macroexpand.
> 
> #(format #t "~%~s~%" (macroexpand '(markup "a" #:column ("b" "c"))))
> ==>
> (make-line-markup (list (make-simple-markup "a")
>                          (make-column-markup (list (make-simple-markup
> "b")
>                                                    (make-simple-markup
> "c")))))
> 
> What it means is that when you write (markup #:column ("a" "b")) it's
> exactly as if you would have written:
> (make-line-markup (list (make-simple-markup "a")
>                          (make-column-markup (list (make-simple-markup
> "b")
>                                                    (make-simple-markup
> "c")))))
> 
> Actually `markup' defines a mini-language for building markup expression
> in Scheme. It aims at mimicking the \markup syntax.
> 
> In my opinion, you should use none of the three versions here.

Thanks for getting it to better syntax.  Neither Kieren nor I have the
understanding you have.  I appreciate your help.

> The first should be:
> #(define-markup-command (test layout props stringA stringB) (string?
> string?)
>     (interpret-markup layout props
>        (markup #:column (stringA stringB))))
> 
> The second should be thrown away.
> 
> The third should be:
> #(define-markup-command (test layout props stringA stringB) (string?
> string?)
>     (interpret-markup layout props
>        (make-column-markup (list stringA stringB))))

If I understand correctly, the two acceptable versions are identical once
the macro expansion happens.  That is,

(markup #:column (stringA stringB)) will expand to

(make-column-markup (list (make-simple-markup stringA)
                          (make-simple-markup stringB)))
As will
(make-column-markup (list stringA stringB))

Is that right?

> 
> There are some cases where the `markup' macro cannot be used, for
> instance:
> 
> #(define (function-that-returns-markups)
>    (list "a" "b" "c"))
> 
> #(define-markup-command (foo layout props) ()
>     (make-markup-command #:column (function-that-returns-markups)))
> 
> There, `markup' is limited in that you cannot write:
>    (markup #:column (function-that-returns-markups))
> as it would think that `function-that-returns-markups' is a markup, as
> stringA and stringB in:
>    (markup #:column (stringA stringB))
> 
> Also, when you have only one markup command call, using the make-xxxx-
> markup
> function is quick enough.
> 
> But in other cases, I don't see why you recommend not using the `markup'
> macro: at least, reading it is easier as it is close to \markup syntax.
> See how verbose is the expansion (that you propose to use) compared to
> the
> original `markup' expression...

Primarily because of the confusion I have about when I can use it and when
not.

But I probably spoke too hastily.

Thanks for the clarification; it will go in my NR6 revision file!

Thanks,

Carl





reply via email to

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