Add step proc for symbols

This commit is contained in:
Emery Hemingway 2023-05-14 22:56:00 +01:00
parent eeef9860cf
commit 7718227662
1 changed files with 8 additions and 0 deletions

View File

@ -273,6 +273,14 @@ func step*(pr, idx: Preserve): Option[Preserve] =
if i < pr.len:
result = some(pr[i])
func step*[E](pr: Preserve[E]; key: Symbol): Option[Preserve[E]] =
## Step into dictionary by a `Symbol` key.
if pr.isDictionary:
for (k, v) in pr.dict.items:
if k.isSymbol and k.symbol == key:
result = some(v)
break
proc `[]=`*(pr: var Preserve; key, val: Preserve) =
## Insert `val` by `key` in the Preserves dictionary `pr`.
for i in 0..pr.dict.high: