[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problems defining markup function to draw lines.
From: |
Aaron Hill |
Subject: |
Re: Problems defining markup function to draw lines. |
Date: |
Sat, 22 Dec 2018 00:58:53 -0800 |
User-agent: |
Roundcube Webmail/1.3.6 |
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
- Re: synchronization of feathered beams, (continued)
- Re: synchronization of feathered beams, Thomas Morley, 2018/12/21
- Re: synchronization of feathered beams, Kieren MacMillan, 2018/12/21
- Re: synchronization of feathered beams, Reggie, 2018/12/21
- Re: synchronization of feathered beams, Thomas Morley, 2018/12/21
- Re: synchronization of feathered beams, Reggie, 2018/12/21
- Re: synchronization of feathered beams, Carl Sorensen, 2018/12/21
- Re: synchronization of feathered beams, Thomas Morley, 2018/12/21
- Re: synchronization of feathered beams, Reggie, 2018/12/21
- Re: synchronization of feathered beams, Thomas Morley, 2018/12/21
- Problems defining markup function to draw lines., Mike Stickles, 2018/12/21
- Re: Problems defining markup function to draw lines.,
Aaron Hill <=
- Re: Problems defining markup function to draw lines., Pierre Perol-Schneider, 2018/12/22
- Re: Problems defining markup function to draw lines., Mike Stickles, 2018/12/22
- Re: Problems defining markup function to draw lines., Trevor, 2018/12/22
- Re: Problems defining markup function to draw lines., Reggie, 2018/12/22
- Re: synchronization of feathered beams, Reggie, 2018/12/24
- Re: synchronization of feathered beams, Kieren MacMillan, 2018/12/24
- Re: synchronization of feathered beams, Reggie, 2018/12/24
- Re: synchronization of feathered beams, Reggie, 2018/12/24
- Re: synchronization of feathered beams, Kieren MacMillan, 2018/12/24
- Re: synchronization of feathered beams, Kieren MacMillan, 2018/12/24