still rather more proud of this code than I should be

Years ago, I wrote this tiny subroutine in PostScript:

/box { % draw a box given lower left and upper right corner coordinates
  2 copy moveto
  3 index exch lineto
  3 -1 roll 2 index lineto
  exch lineto
  closepath
} def

All it does is define a rectangular path given by four numbers. So to draw a box from (0,0) to (100,50), you’d say

0 0 100 50 box
stroke

This code still pleases me because:

  • it accepts arguments in a sensible order
  • it uses no local variables, relying purely on the stack
  • no spare values have to be popped from the stack at any time.