Thread: Postscript Programming Question

  1. #1
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970

    Postscript Programming Question

    The following Postscript program draws a rectangular box.

    Code:
    /mybox {
      /Yh exch def
      /Xw exch def
      /Y0 exch def
      /X0 exch def
      
      newpath
        X0 Y0 moveto
        0 Yh rlineto
        Xw 0 rlineto
       % 0 Yh neg rlineto
       closepath
    } def
    
    50 50 300 500 mybox stroke
    It works, but I don't understand how the following line is executed.

    Code:
    /Yh exch def
    I've read a bunch of tutorials, and apparently exch exchanges the top 2 operands in the stack, while def is used to define a variable. But I don't see how the combination of the two operands sets Yh = 500. Maybe somebody can enlighten me.

    Edit!

    I think I understand it now.

    What exch does is to change

    500 /Yh exch def

    into

    /Yh 500 def

    Which sets Yh = 500.

    I came to this conclusion after Googling how "exch def" works and found this PDF which explains it.
    Last edited by Dante Shamest; 10-10-2005 at 06:48 PM.

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    You can see now why only Sun was crazy enough to actually write a window manager using this ancient gibberish, can't you?

  3. #3
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    I didn't know that. Searching on Wikipedia found this article about NeWs (Network extensible Window System). Is this the one you're talking about?

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Yep. It was a good idea at the time, I suppose...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM