[metapost] variable parameter list

Dan Luecking luecking at uark.edu
Tue Feb 14 18:10:30 CET 2006


At 05:13 AM 2/14/2006, you wrote

> > >     save = ;
> > >     let = _equals _assign ;
> >
> > What is the difference in '=' before and after these changes? As I
> > understand it '=' refers to _assign which in turn refers to _equals
> > which is the same as '='.
>
>_equals has the original definition of "=". _assign is needed to
>hide the operation from the for-loop and return something the
>loop can work with. I don't know how the loop works internally,
>thus the solution was found mainly by trial and error :)

A for-loop of the form

  for _x_ = T:

requires T to be one of two types:

   m step n until

where m and n are numeric expressions, or

   X, Y, ..., Z

where X, Y, etc., are *expressions* (of any type). Each expression is 
evaluated and the value is stored in a capsule, which then replace the
_x_ in the body of the loop (much like macro parameters of type expr).

Something like
   ..., mykey = 1, ...
is a boolean expression, so it is valid, but clearly doesn't have
the intended effect. Some packages get around this by using strings:
   ..., "mykey = 1", ...
This requires scantokens (and often requires typing hundreds of
doublequotes). In your code, _assign was defined by primarydef
and so
   ..., mykey _assign 1, ...
is an expression. The fact that its return value is never used
suggests that it needn't actually have a return value. A for-loop
doesn't care if the expressions are empty, it just skips to the
next. I didn't test this, however.


Dan


Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
"Be kind. Every person you meet is fighting a hard battle." - Anon.



More information about the metapost mailing list