lilypond-user
[Top][All Lists]
Advanced

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

Re: Problems defining markup function to draw lines.


From: Mike Stickles
Subject: Re: Problems defining markup function to draw lines.
Date: Sat, 22 Dec 2018 10:16:31 -0500
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3

Thanks, Aaron!  Following your notes, I corrected the path to:

\path #0.3 #`((moveto ,xoff ,yoff) (lineto ,(+ 2 xoff) ,(+ 4 yoff)) (moveto ,(+ 1 xoff) ,yoff) (lineto ,(+ 3 xoff) ,(+ 4 yoff)))

and now it works like a charm.  And that Scheme intro book looks like exactly what I need to help head off similar confusions in the future.  "Relatively new to the language" is spot-on for me :-)

- Mike

On 12/22/2018 3:58 AM, Aaron Hill wrote:
On 2018-12-21 8:15 pm, Mike Stickles wrote:
But when I try to implement the numbers, I get errors no matter what I
do. This (while it doesn't work) shows what I'm trying to get to:

#(define-markup-command (double-box layout props xoff yoff) (number? number?)
  (interpret-markup layout props
    #{
        \markup {
            \with-dimensions #'(0 . 0) #'(0 . 0)
            \path #0.3 #'((moveto xoff yoff) (lineto (+ xoff 2) (+
yoff 4)) (moveto (+ xoff 1) yoff) (lineto (+ xoff 3) (+ yoff 4)))
        }
    #}
))


Any ideas on what I'm doing wrong?

You are hitting an common stumbling block in Scheme regarding quoting.  Urs has a great Scheme introduction book[1] online that would be good reviewing as it sounds like you may be relatively new to the language.

[1]: https://scheme-book.ursliska.de/

\path needs a list of commands, where an individual command consists of a symbol (defining the particular command) and then its arguments, which are typically just numbers.

To construct a suitable \path argument in Scheme, we use the list function:

    (list ((quote moveto) 1 2) ((quote lineto) 3 4))

This is the explicit list construction technique, and we are also using the explicit invocation of quote.  We need quote here because "moveto" and "lineto" are symbols.  We do not want the value behind the symbols, just the symbols as things on their own.

Scheme (technically LISP) developed a number of shorthands for common constructions.  You can construct a list more succinctly this way:

    '((moveto 1 2) (lineto 3 4))

The leading quote puts us in quote mode so that we can simply type "moveto" by itself.  We also no longer need to say list explicitly, as we'll end up with a list.  The numbers are technically being quoted here, but a quoted number literal works.

But what if we need a variable?  We cannot use the same construction, because our variables will end up quoted rather than using the value behind the name.  One solution is to go back to the more explicit invocation:

    (list ('moveto a b) ('lineto c d))

Here we are still using the shortcut quote for the symbols, but everything else will be resolved properly in this form.  This is a perfectly acceptable option, but some folks prefer the shorthand of quoting.  The alternate solution is quasi-quoting:

    `((moveto ,a ,b) (lineto ,c ,d))

This one looks funny at first, but the difference is the use of the grave as opposed to the apostrophe.  This sets up a quasi-quoting mode that behaves nearly identical to normal quoting, except we can use a comma to "unquote".  And here the variables will be evaluated as expected.


-- Aaron Hill

_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user

reply via email to

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