[metapost] Processing comma separated values
Dan Luecking
luecking at uark.edu
Fri Feb 26 20:56:58 CET 2010
At 01:32 AM 2/26/2010, Taco Hoekwater wrote:
>Aditya Mahajan wrote:
>>Hi,
>>What is the canonical way of processing a list of comma separated
>>values in metapost. I want to write a helper macro for the boxes
>>package so that
[...]
>>boxsep(a,b,c,d) = p ;
>>
>>expands to
>>
>>b.w - a.e = c.w - b.e = d.w - c.e = p ;
>
>I do not have time to write a full answer, but the way to
>process a list of argument values is something like this:
>
>def boxsep (text a) =
> forsuffixes _a=a:
> show _a;
> endfor
>enddef;
I have already exchanged email with Aditya Mahajan,
but forgot to "Reply All" to include the list. The
results of our exchange were the following two examples:
%This works only for pair variables (which was the given case):
def boxsep (suffix A)(text T) =
def _prev_suffix = A enddef;
pair _dummy_pair;
forsuffixes _S = T:
_S.w - _prev_suffix.e = _dummy_pair;
def _prev_suffix = _S enddef;
endfor
_dummy_pair
enddef
% This can generate equations for any list of two or
% more variables of the same type (for which subtraction
% makes sense):
def boxsep (suffix A,B) (text T) =
def _prev_suffix = B enddef;
B.w - A.e
forsuffixes _S = T:
= _S.w - _prev_suffix.e
hide (def _prev_suffix = _S enddef;)
endfor
enddef;
The main problem was to remember the previous suffix
so as to subtract it from the current one.
Best wishes,
Dan
Daniel H. Luecking
Department of Mathematical Sciences
Fayetteville, Arkansas
http://www-cs-faculty.stanford.edu/~knuth/iaq.html
More information about the metapost
mailing list