[metapost] augment drawoptions

Stephan Hennig mailing_list at arcor.de
Wed Apr 16 00:37:10 CEST 2008


Taco Hoekwater schrieb:

> You cannot save _op_ because it is a macro, not a variable.

It seems macros /can/ be saved.

def foo=1 enddef;
show foo;

begingroup
save foo;
  def foo=2 enddef;
  show foo;
endgroup;

show foo;

end


Based on that observation addtodrawoptions can be implemented as show
below.  Here, _op_ is always saved with respect to the current group.  A
global macro _op_tmp_ serves as a temporary storage for the value of
_op_.  What's wrong with that?  Can we refrain from using _op_tmp_ here,
too?

Best regards,
Stephan Hennig


def addtodrawoptions(text t) =
  expandafter def expandafter _op_tmp_ expandafter = _op_ enddef;
  save _op_;
  expandafter def expandafter _op_ expandafter = _op_tmp_ t enddef;
enddef;

beginfig(1);
  drawoptions(withcolor red);% Set colour.
  begingroup
    addtodrawoptions(withpen pencircle scaled 4bp);
    draw fullcircle scaled 100;
    begingroup
      addtodrawoptions(withpen pencircle withcolor green);
      draw fullcircle scaled 90;
      addtodrawoptions(withpen pencircle withcolor blue);
      draw fullcircle scaled 80;
    endgroup;
    draw fullcircle scaled 70;
  endgroup;
  draw fullcircle scaled 50 ;
endfig;
end


More information about the metapost mailing list