A reckoner seed: dict over a list of pairs — machines/seeds/seeddict.shoddy
seeddict bridges DPUT DGET DHAS DKEYS into
the reckoner calculator. A "dict" is a dictionary: values stored under
names, called keys. At the keyboard it is an ordinary LIST
cell whose elements are PAIR cells — no new stack
case. That is the same discipline matrix's seed
applies to arrays, applied here to association lists (lists of key-value
pairs). "rate" 0.05 PAIR 1 GATHER is a one-entry dict, and
DPUT grows it.
Not delegated to dict.shoddy's own
words, on purpose. DictGet, DictHas
and DictPut compare keys with the language's native
=. That operator compares a List or a
Program cell by identity — are they the same object?
— rather than by value. This seed keys by
CutEqual instead, the same
structural (by-contents) equality = already gives every
other stack word. That is what lets "rate" and a computed
{ 1 2 } key alike behave the way DUP = already
promised they would. DGET is also guarded where
DictGet isn't. DictGet Errors on a
missing key; DGET answers a refusal instead, naming the
key.
Let st0 = RckSeedDict(RckNew())
RckEval(st0, Chr(34) & "rate" & Chr(34) & " 0.05 PAIR 1 GATHER") ' x: one-entry dict
RckEval(st0, Chr(34) & "term" & Chr(34) & " 12 DPUT") ' x: two-entry dict
RckEval(st0, Chr(34) & "rate" & Chr(34) & " DGET") ' x: 0.05
| Word | Description |
|---|---|
| DHAS ( d k -- flag ) | Whether the dict has an entry for key k. |
| DGET ( d k -- v ) | The value stored under key k; refuses a missing key, naming it. |
| DPUT ( d k v -- d ) | The dict with key k set to v, added if it was not already there. |
| DKEYS ( d -- list ) | The dict's keys, in the order they were entered. |
| User | How | |
|---|---|---|
| halifax | DPUT, DGET, DHAS and DKEYS: a keyed store on the stack, beside the engine's own numbered registers. | |
| sparky | Sparky folds it too, so a model calling eval reaches the same words halifax puts at a prompt. |
A mill claims this seed by folding RckSeedDict over its reckoner
state, which is all halifax does.
| Machine | Why | |
|---|---|---|
| cuttle | CutEqual keys an association list of CutPair cells structurally, in place of the language's native =. | |
| reckoner | RckReg, RckSeeding and the argument readers every registered word is built from. | |
| seq | List plumbing under the LIST-of-PAIR reader every word here shares. |