Le 29 janv. 09 à 16:29, Carl D. Sorensen a écrit :
On 1/29/09 7:12 AM, "Kieren MacMillan" <kieren_macmil...@sympatico.ca>
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.
`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.
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))))
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...
Nicolas
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user