@@ -546,3 +546,57 @@ For repetitive tests, use template procedures:
546546
547547(INVALID) /bwipp.encoderBadData er_tmpl
548548```
549+
550+
551+ ## PostScript Language paradigms
552+
553+ Pay attention to the direction of roll:
554+
555+ (a) (b) (c) 3 1 roll => (c) (a) (b)
556+ (a) (b) (c) 3 -1 roll => (b) (c) (a)
557+
558+ Understand the offset used by index:
559+
560+ (a) (b) (c) 1 index => (a) (b) (c) (b)
561+
562+ Inserting stack elements requires index adjustment:
563+
564+ (a) (b) (c) /x 1 index def => (a) (b) (c) ; and x = (c), not (b) due to /x on the stack!
565+
566+ Understand that readonly does not affect its argument:
567+
568+ ``` postscript
569+ /a [ 1 2 3 ] def % a is writable
570+ a readonly pop % a is still writable; achieves nothing
571+ /c a readonly def % c is not writable; a remains writable
572+ ```
573+
574+ Invalidating a boolean placed first on the stack is a common way to perform multiple tests that must pass:
575+
576+ ``` postscript
577+ true % Assume good until...
578+ a 1 eq { pop (Error: a can't be 1) false } if % ... error encountered: Replace "true" with "false (error message)"
579+ a 9 eq { pop (Error: a can't be 9) false } if
580+ b 5 gt { pop (Error: b must be 5 or less) false } if
581+ % ... More tests ...
582+ not { % Check status
583+ (An error occurred) ==
584+ == % Emit error message on stack
585+ stop % Do unwinding instead
586+ } if
587+ % If we get here, all is well and no boolean left on the stack
588+ ```
589+
590+ PLRM terminology is confusing:
591+
592+ As a result of the following command:
593+
594+ /a [ 1 2 3 ] def
595+ /b a def
596+
597+ - a is referred to as the "object" (within the currentdict)
598+ - The --array-- created by "] " is referred to as "the storage for the object in VM" (either global or local depending on globalstatus)
599+ - b is also an "object" that refers to the same VM storage as a
600+
601+ The terminology differs from languages where the array itself would be an object and a and b would be names / references.
602+
0 commit comments