Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
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">
<code>
% Level 1 declaration
3 dict dup begin
Line 952:
>>
 
% Both methods leave the dictionary on the operand stack
</codesource>
 
Dictionaries can be accessed directly using '''get''' or implicitly by placing the dictionary on the dictionary stack using '''begin''':
 
<source lang="postscript">
<code>
% With the previous two dictionaries still on the operand stack
/red get print % outputs 'rot'
Line 962:
begin
green print % outputs 'vert'
end</code>
</source>
 
Dictionary contents can be iterated through using '''forall''', though not in any particular order:
 
<source lang="postscript">
<code>
% Level 2 example
<<
Line 972 ⟶ 973:
/That 2
/Other 3
>> {exch =print ( is ) print ==} forall
</codesource>
May well output:
<source lang="postscript">
<code>
That is 2
This is 1
Other is 3
</codesource>
 
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">
<code>
% define a dictionary for easy reuse:
/MyDict <<
Line 994 ⟶ 997:
 
% remove something
MyDict /rouge undef
</codesource>
 
=== Prolog ===