Associative array/Creation: Difference between revisions
→{{header|langur}}
(→Insitux: implementation) |
Langurmonkey (talk | contribs) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 2,749:
# typed (coerces to float)</syntaxhighlight>
=={{header|EasyLang}}==
# use array of array for this
▲</syntaxhighlight>
▲proc indexAssoc index . array[][] item .
▲ for i = 1 to len array[][]
▲ if array[i][1] = index
▲ item = array[i][2]
▲ break 2
.
.
item$ =
.
proc
for i
if
.
.
.
clothing$[][] = [ [ "type" "t-shirt" ] [ "color" "red" ] ]
clothing$[][] &= [ "size" "xl" ]
#
hashSet "color" "green" clothing$[][]
hashGet "color" clothing$[][] col$
print col$
</syntaxhighlight>
Line 3,932 ⟶ 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 =
# may assign with existing or non-existing hash key (if hash is mutable)
Line 6,034 ⟶ 6,035:
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var hash = Hash
key1 => 'value1',
key2 => 'value2',
)
# Add a new key-value pair
hash{:key3} = 'value3'
=={{header|Slate}}==
Line 6,418 ⟶ 6,419:
=={{header|Wren}}==
Wren has a Map class built in.
<syntaxhighlight lang="
fruit[1] = "orange" // associates a key of 1 with "orange"
fruit[2] = "apple" // associates a key of 2 with "apple"
Line 6,447 ⟶ 6,448:
null
</pre>
=={{header|XLISP}}==
|