Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!agate!ucbvax!decwrl!adobe!greid From: greid@adobe.com (Glenn Reid) Newsgroups: comp.lang.postscript Subject: commenting out blocks of code Message-ID: <1100@adobe.UUCP> Date: 23 Aug 89 21:49:45 GMT Sender: news@adobe.COM Reply-To: greid@adobe.COM () Organization: Adobe Systems Incorporated, Mountain View Lines: 54 I've been writing serious PostScript code for over 4 years and I just thought of this. I wonder what that means.... There is only one comment mechanism in PostScript, which is the % character. It comments through the end of the line. So, to comment out a block of code, you do something like this: % /F { %def % findfont % exch scalefont % setfont % } bind def In fact, I've written an emacs macro to do this very thing, and also to delete them as necessary. Yesterday it dawned on me that there is another mechanism for effectively commenting out blocks of code that is a lot easier. It doesn't really comment out the code, but it keeps it from executing, which amounts to the same thing, since you typically only do it while you're debugging: { % <--------- add this line /F { %def findfont exch scalefont setfont } bind def } pop % <--------- also this line It's only two lines, regardless of the number of lines in between (assuming you don't overflow the operand stack, that is). Reminiscent of Pascal comments, methinks. Since procedure bodies are always constructed as arrays with deferred execution, you just force the code into a procedure then pop it from the stack. It works with essentially all PostScript constructs in between, with the exception of mismatched (), <>, or {} delimiters and perhaps something else. Since { is easy to miss, I now use something a little more noticeable, like this: { %%%%%%%%%%% } pop %%%%%%% Just thought I would pass this on. I suppose the rest of you have been using this technique for years :-) Glenn Reid Adobe Systems