Hi Michael,

To say I'm no expert in Scheme is a vast understatement. However, I think I found the answer to this one.
Just in order to reassure you a bit:

 Basically, as I understand things, this bit:

           #'((lineto 0 hgt)


Accosrding to my rather vague understanding of Scheme syntax the ' between the # and the 1st ( is saying don't interpret anything in that expression, just pass it as is. Which means that your variable hgt isn't getting passed as a variable but is getting passed as simply a series of three characters.
Better make that: hgt is passed as the "symbol" hgt (usually entered as 'hgt in Scheme). Other than that, you're right.
What seems to be needed (and what made this appear to work here) is to use what's called quasiquoting. Basically, it lets you designate certain bits within an expression as "this part should be interpreted before getting passed on". This entails changing the above line to:

#`((lineto 0 ,hgt)

By changing the ' into a ` (BTW, that's the one that on my keyboard is up near the top left, just under the Escape key) you say that there's something in the following expression that will need interpreted. Then the comma before the variable name points out which item to interpret.

That's correct (modulo the term "interpret" where "evaluate" is more common), and quasiquoting indeed is the right way to construct complicated list/pair structures containing lots of symbols and some variables that should be evaluated.

There's one other way which is sometimes useful (but admittedly won't simplify the present use case much):

#`((lineto 0 ,hgt) (closepath))

is the a list with two elements, namely
- the 3-element list containing 'lineto, 0 and the value of the variable hgt
- the 1-element list containing the symbol 'closepath.

This may also be written as:

#(list (list 'lineto 0 hgt) (list 'closepath))

or, mixing the two styles,

#(list (list 'lineto 0 hgt) '(closepath))

Lukas

Reply via email to