Associative array/Creation: Difference between revisions

 
(3 intermediate revisions by 3 users not shown)
Line 2,759:
.
item$ = ""
.
proc hashSet ind$ val$ . ar$[][] .
for i to len ar$[][]
if ar$[i][1] = ind$
ar$[i][2] = val$
return
.
.
.
clothing$[][] = [ [ "type" "t-shirt" ] [ "color" "red" ] ]
clothing$[][] &= [ "size" "xl" ]
#
hashSet "color" "green" clothing$[][]
hashGet "color" clothing$[][] col$
print col$
Line 3,924 ⟶ 3,933:
Hash keys in langur may be numbers or strings. Number keys are simplified, so that 1.0 is the same key as 1.
 
<syntaxhighlight lang="langur">var .hash = h{1: "abc", "1": 789}
 
# may assign with existing or non-existing hash key (if hash is mutable)
Line 6,026 ⟶ 6,035:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var hash = Hash.new(
key1 => 'value1',
key2 => 'value2',
);
 
# Add a new key-value pair
hash{:key3} = 'value3';</syntaxhighlight>
 
=={{header|Slate}}==
Line 6,410 ⟶ 6,419:
=={{header|Wren}}==
Wren has a Map class built in.
<syntaxhighlight lang="ecmascriptwren">var fruit = {} // creates an empty map
fruit[1] = "orange" // associates a key of 1 with "orange"
fruit[2] = "apple" // associates a key of 2 with "apple"
Line 6,439 ⟶ 6,448:
null
</pre>
 
 
=={{header|XLISP}}==
890

edits