I'm a bit late to the party and the explanations which precede this post cover pretty much everything, but to answer your specific questions:
- Set a variable tbox:off to the result of a condition. Pause here - where is tbox:off declared? I don't see it in the c:tbox function header.
Indeed,
tbox:off is not declared at all: this variable has global scope and is defined within the active document namespace (as opposed to having scope limited to the function in which it is declared). The use of a global variable for this application allows the last used offset factor to be remembered within the active drawing session.
- Now, reading from the inside out that interesting statement...
- Initialize tbox:off to 0.35
Correct, but only if
tbox:off already holds a non-nil value: if this global variable already holds a non-nil value, the first test expression for the
cond statement will yield a non-nil value (and thereby cease evaluation of subsequent test expressions) and such value will be returned by the
cond statement.
- That is then enclosed in parens a second time - because?
Because the
setq expression itself forms the
cond test expression - it could equivalently be formatted in the following way, which may help you to dissect the various components of the
cond expression:
- Now, test the value of tbox:off - which at this stage I think is undefined
This test is evaluated first, and may yield the value of the
tbox:off variable, if the program has already been used in the active drawing session.
- if it's non-nil - set tbox:off to 0.35. Uh...I'm assuming this is some kind of
protected initialization but the mechanism escapes me.
The mechanism is essentially equivalent to a basic
if statement such as the following:
- Now, take the (apparently) numberic result of that conditional, convert to a string, and call (getdist)
The result of the
cond expression will always be numeric (unless of course the global variable tbox:off is independently redefined) because if
tbox:off is null, it will be assigned the value 0.35, else, it will yield the value assigned on a previous evaluation (which must be numeric given that
getdist returns a numeric value).