Associative array/Creation: Difference between revisions
Content added Content deleted
Line 405: | Line 405: | ||
J% = INSTR(dict$, CHR$(0), I%) |
J% = INSTR(dict$, CHR$(0), I%) |
||
= MID$(dict$, I%, J% - I%)</lang> |
= MID$(dict$, I%, J% - I%)</lang> |
||
=={{header|Bracmat}}== |
|||
The hash is the only built-in Bracmat class. It is best used for e.g. a large dictionary, when manipulation of a very long list of key/value pairs with pattern matching would become too CPU-intensive. The same key can be stored with different values, as the example shows. If that is not desirable, the key (and its value) should be removed first. |
|||
<lang bracmat> new$hash:?myhash |
|||
& (myhash..insert)$(title."Some title") |
|||
& (myhash..insert)$(formula.a+b+x^7) |
|||
& (myhash..insert)$(fruit.apples oranges kiwis) |
|||
& (myhash..insert)$(meat.) |
|||
& (myhash..insert)$(fruit.melons bananas) |
|||
& out$(myhash..find)$fruit |
|||
& (myhash..remove)$formula |
|||
& (myhash..insert)$(formula.x^2+y^2) |
|||
& out$(myhash..find)$formula;</lang> |
|||
Output: |
|||
<pre>(fruit.melons bananas) (fruit.apples oranges kiwis) |
|||
formula.x^2+y^2</pre> |
|||
=={{header|Brat}}== |
=={{header|Brat}}== |