[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lilypond-user
Subject:    Re: Problems defining markup function to draw lines.
From:       Mike Stickles <mike () grtbooks ! com>
Date:       2018-12-22 15:16:31
Message-ID: 5999a571-9f67-9960-e522-c32f168ad27b () grtbooks ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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
> lilypond-user@gnu.org
> https://lists.gnu.org/mailman/listinfo/lilypond-user

[Attachment #5 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Thanks, Aaron!   Following your notes, I corrected the path to:</p>
    <p><tt><font color="#660000">\path #0.3 #`((moveto ,xoff ,yoff)
          (lineto ,(+ 2 xoff) ,(+ 4 yoff)) (moveto ,(+ 1 xoff) ,yoff)
          (lineto ,(+ 3 xoff) ,(+ 4 yoff)))</font></tt><br>
    </p>
    <p>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
      :-)<br>
    </p>
    <p>- Mike<br>
    </p>
    <div class="moz-cite-prefix">On 12/22/2018 3:58 AM, Aaron Hill
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:de9f3aa6355ac7b4398ec89d76160a6b@hillvisions.com">On
      2018-12-21 8:15 pm, Mike Stickles wrote:
      <br>
      <blockquote type="cite">But when I try to implement the numbers, I
        get errors no matter what I
        <br>
        do. This (while it doesn't work) shows what I'm trying to get
        to:
        <br>
        <br>
        #(define-markup-command (double-box layout props xoff yoff)
        (number? number?)
        <br>
           (interpret-markup layout props
        <br>
               #{
        <br>
                      \markup {
        <br>
                             \with-dimensions #'(0 . 0) #'(0 . 0)
        <br>
                             \path #0.3 #'((moveto xoff yoff) (lineto (+ xoff 2)
        (+
        <br>
        yoff 4)) (moveto (+ xoff 1) yoff) (lineto (+ xoff 3) (+ yoff
        4)))
        <br>
                      }
        <br>
               #}
        <br>
        ))
        <br>
        <br>
        <br>
        Any ideas on what I'm doing wrong?
        <br>
      </blockquote>
      <br>
      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.
      <br>
      <br>
      [1]: <a class="moz-txt-link-freetext" \
href="https://scheme-book.ursliska.de/">https://scheme-book.ursliska.de/</a>  <br>
      <br>
      \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.
      <br>
      <br>
      To construct a suitable \path argument in Scheme, we use the list
      function:
      <br>
      <br>
             (list ((quote moveto) 1 2) ((quote lineto) 3 4))
      <br>
      <br>
      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.
      <br>
      <br>
      Scheme (technically LISP) developed a number of shorthands for
      common constructions.   You can construct a list more succinctly
      this way:
      <br>
      <br>
             '((moveto 1 2) (lineto 3 4))
      <br>
      <br>
      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.
      <br>
      <br>
      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:
      <br>
      <br>
             (list ('moveto a b) ('lineto c d))
      <br>
      <br>
      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:
      <br>
      <br>
             `((moveto ,a ,b) (lineto ,c ,d))
      <br>
      <br>
      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.
      <br>
      <br>
      <br>
      -- Aaron Hill
      <br>
      <br>
      _______________________________________________
      <br>
      lilypond-user mailing list
      <br>
      <a class="moz-txt-link-abbreviated" \
href="mailto:lilypond-user@gnu.org">lilypond-user@gnu.org</a>  <br>
      <a class="moz-txt-link-freetext" \
href="https://lists.gnu.org/mailman/listinfo/lilypond-user">https://lists.gnu.org/mailman/listinfo/lilypond-user</a>
  <br>
    </blockquote>
  </body>
</html>



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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic