Associative array/Creation: Difference between revisions

(→‎Insitux: implementation)
Line 2,749:
# typed (coerces to float)</syntaxhighlight>
=={{header|EasyLang}}==
</syntaxhighlight>
EasyLang does not really have associative arrays, but arrays of arrays type is a good substitute.
# use array of array for this
<syntaxhighlight lang="easylang">
proc indexStrAssochashGet indexind$ . arrayar$[][] item$ .
associative$[][] = [ [ 1 "associative" ] [ 2 "arrays" ] ]
for i = 1 to len arrayar$[][]
</syntaxhighlight>
if arrayar$[i][1] = indexind$
And here are functions for indexing associative arrays:
item$ = arrayar$[i][2]
<syntaxhighlight lang="easylang">
break 2return
proc indexAssoc index . array[][] item .
for i = 1 to len array[][]
if array[i][1] = index
item = array[i][2]
break 2
.
.
item = number "nan"
.
proc indexStrAssoc index$ . array$[][] item$ .
for i = 1 to len array$[][]
if array$[i][1] = index$
item$ = array$[i][2]
break 2
.
.
item$ = ""
.
clothing$[][] = [ [ "type" "t-shirt" ] [ "color" "red" ] ]
clothing$[][] &= [ "size" "xl" ]
#
hashGet "color" clothing$[][] col$
print col$
</syntaxhighlight>
 
2,043

edits