2013/02/15: Monkey patching in postscript

In postscript, the bind operator replaces executable operator names in the top-most stack element by their values in the current dictionary stack. This can be used to redefine a function in terms of its old meaning, effectively advising it. If, for example, I want to double the width of all lines in an eps, I can simply wrap it as follows.


%!
gsave
  /setlinewidth {2 mul setlinewidth} bind def
  1 setlinewidth

  % ...

grestore