I am not sure I understand the semantics of Postscript dictionaries. What is the difference if a 'def' is used when defining an entry to a dictionary as opposed to just listing the key value pair. Below, I define /a and /b in dictionary /d. /a is defined using 'def'; /b is defined using a ky value pair. When printing out /d with the '===' operator, we only see /b. If we load /d onto the dictionary stack, we can access and print both /a and /b. If we do a get on /d /b we get back the value of /b. But if we do a get on /d /a, we get an undefined error.
Could someone help me understand why /a is not defined/visable using 'get' on dictionary /d, why it does not show up when printing /d and why it is accessible/defined when we load /d onto the dictionary stack?
The definition of the 'def' operator is pretty straightforward:
def - associates key with value in the current dictionary—the one on the top of the dic- tionary stack (see Section 3.4, “Stacks”). If key is already present in the current dictionary, def simply replaces its value; otherwise, def creates a new entry for key and stores value with it. - p.568 Postscript Language Reference 3rd edition
In this case, I see the currentdict at the time of defining /a as being /d. But 'get' can't see it. However, it is in the dictionary as when you load the dictionary onto the dictionary stack, it is defined.
/d <<
/a 22 def
/b 33
>> def % Define dictionary 'd'
d === % Print out contents of d; Prints /b 33 but no /a
d begin % Push d onto the dictionary stack
a = % Prints value of d/a '22'
b = % Prints value of d/b '33'
end % Pop d off of the dictionary stack
d /b get = % Prints value of d/b '33'
d /a get = % Error /undefine. Cannot find /a in d
Output (using ghostscript):
$ gs -q -dALLOWPSTRANSPARENCY -dBATCH -dNOPAUSE -dQUIET -dNOSAFER -sDEVICE=pdfwrite -o tmp_test.pdf tmp_test.ps
<< /b 33 >>
22
33
33
Error: /undefined in --get--
Operand stack:
--dict:1/1(L)-- a
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:795/1123(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Current file position is 317
GPL Ghostscript 10.01.2: Unrecoverable error, exit code 1
$