Associative array/Creation: Difference between revisions
m
BaCon, BASIC256, and BBC BASIC moved to the BASIC section.
(→{{header|Ruby}}: add examples of literals; format code with spaces as conventional) |
m (BaCon, BASIC256, and BBC BASIC moved to the BASIC section.) |
||
Line 2,087:
("baz" 77)) ls2map !</syntaxhighlight>
=={{header|
<syntaxhighlight lang="qbasic">DECLARE associative ASSOC STRING
Line 2,102 ⟶ 2,103:
String keys, with ASSOC to a given data type. Sizing is dynamic.
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">global values$, keys$
dim values$[1]
Line 2,218 ⟶ 2,219:
e endive
c carrot</pre>
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic"> REM Store some values with their keys:▼
PROCputdict(mydict$, "FF0000", "red")▼
PROCputdict(mydict$, "00FF00", "green")▼
PROCputdict(mydict$, "0000FF", "blue")▼
REM Retrieve some values using their keys:▼
PRINT FNgetdict(mydict$, "green")▼
PRINT FNgetdict(mydict$, "red")▼
END▼
DEF PROCputdict(RETURN dict$, value$, key$)▼
IF dict$ = "" dict$ = CHR$(0)▼
dict$ += key$ + CHR$(1) + value$ + CHR$(0)▼
ENDPROC▼
DEF FNgetdict(dict$, key$)▼
LOCAL I%, J%▼
I% = INSTR(dict$, CHR$(0) + key$ + CHR$(1))▼
IF I% = 0 THEN = "" ELSE I% += LEN(key$) + 2▼
J% = INSTR(dict$, CHR$(0), I%)▼
= MID$(dict$, I%, J% - I%)</syntaxhighlight>▼
=={{header|Batch File}}==
Line 2,257 ⟶ 2,281:
"sicko&mumps" = 7
"sicko&bromodrosis" = 8</pre>
▲=={{header|BBC BASIC}}==
▲<syntaxhighlight lang="bbcbasic"> REM Store some values with their keys:
▲ PROCputdict(mydict$, "FF0000", "red")
▲ PROCputdict(mydict$, "00FF00", "green")
▲ PROCputdict(mydict$, "0000FF", "blue")
▲ REM Retrieve some values using their keys:
▲ PRINT FNgetdict(mydict$, "green")
▲ PRINT FNgetdict(mydict$, "red")
▲ END
▲ DEF PROCputdict(RETURN dict$, value$, key$)
▲ IF dict$ = "" dict$ = CHR$(0)
▲ dict$ += key$ + CHR$(1) + value$ + CHR$(0)
▲ ENDPROC
▲ DEF FNgetdict(dict$, key$)
▲ LOCAL I%, J%
▲ I% = INSTR(dict$, CHR$(0) + key$ + CHR$(1))
▲ IF I% = 0 THEN = "" ELSE I% += LEN(key$) + 2
▲ J% = INSTR(dict$, CHR$(0), I%)
▲ = MID$(dict$, I%, J% - I%)</syntaxhighlight>
=={{header|Bracmat}}==
|