Content deleted Content added
Communal t (talk | contribs) m Removed unnecessary Template:DEFAULTSORT. Added to Category:Programming language comparisons. Sorted listing in Category:Associative arrays to Programming language comparison. |
m →PostScript: <source lang="postscript"> |
||
Line 937:
In [[PostScript]], associative arrays are called dictionaries. In Level 1 PostScript they must be created explicitly, but Level 2 introduced direct declaration using the double-brace syntax:
<source lang="postscript">
% Level 1 declaration
3 dict dup begin
Line 952:
>>
% Both methods leave the dictionary on the operand stack
</ Dictionaries can be accessed directly using '''get''' or implicitly by placing the dictionary on the dictionary stack using '''begin''':
<source lang="postscript">
% With the previous two dictionaries still on the operand stack
/red get print % outputs 'rot'
Line 962:
begin
green print % outputs 'vert'
end
</source>
Dictionary contents can be iterated through using '''forall''', though not in any particular order:
<source lang="postscript">
% Level 2 example
<<
Line 972 ⟶ 973:
/That 2
/Other 3
>> {exch =print ( is ) print ==} forall
</ May well output:
<source lang="postscript">
That is 2
This is 1
Other is 3
</ Dictionaries can be augmented (up to their defined size only in Level 1) or altered using '''put''', and entries can be removed using '''undef''':
<source lang="postscript">
% define a dictionary for easy reuse:
/MyDict <<
Line 994 ⟶ 997:
% remove something
MyDict /rouge undef
</ === Prolog ===
|