[metapost] On simulating def with vardef
Nicola
nvitacolonna at gmail.com
Tue Jun 30 11:50:51 CEST 2009
Hi,
I used to think that a vardef behaves like a primary because its
replacement text is surrounded by begingroup/endgroup. But, recently, I
have tried this:
def foo = x enddef;
foo := 1; % Ok, sets x=1
vardef foovar = endgroup gobbled true x gobble begingroup enddef;
foovar := 2; % Not ok: ! Improper `:=' will be changed to `='.
I conclude that the replacement text of a vardef macro is treated as a
primary in any case. Is it correct? Is there a way to have a vardef in
the left hand side of an assignment in some circumstances?
For those who are care, what I would like to achieve is something like:
vardef suffixof prefixof @# =
endgroup gobbled true @# gobble begingroup
enddef;
vardef prefixof x@# =
endgroup gobbled true suffixof #@.@ gobble begingroup
enddef;
so that
prefixof x.a := 0;
would set x=0 (I know that I can use 'str', but I would like to know if
this is possible without it).
Thanks,
Nicola
More information about the metapost
mailing list