A reckoner seed: dict over a list of pairs (machines/seeds/seeddict.shoddy)
seeddict bridges DPUT DGET DHAS DKEYS DPATH 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, with 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
=. This seed keys by
CutEqual instead, the comparison
that knows every cell's kind. The two agree on a List key
now that = compares lists by their items; a
Program cell still compares by identity under
=, and CutEqual is what lets a computed
{ 1 2 } key and a program key alike behave the way
DUP = already promised they would. DGET is also guarded where
DictGet is not. 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. |
| DPATH ( d path -- v ) | The value at the end of a path: a LIST of STRING keys and NUMBER indices, each step a DGET or an NTH on the value so far. Refuses naming the step that failed; an empty path answers d itself. A parsed JSON, XML or HTML document, a CSVPAIRS row and an HTTP header dict all walk with it. |
| 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. |