diff --git a/example/KeyValueStore.forth b/example/KeyValueStore.forth index 0079357..483ae15 100644 --- a/example/KeyValueStore.forth +++ b/example/KeyValueStore.forth @@ -49,10 +49,12 @@ This could be improved: - factor out the update and add entry actions ~~~ +:kv:update-entry (vsD-) kv:lookup kv:value store ; +:kv:add-entry (vsD-) here over [ [ fetch , , , ] dip ] dip store ; + :kv:set (vsD-) dup-pair kv:lookup n:-zero? - [ kv:lookup kv:value store ] - [ here over [ [ fetch , , , ] dip ] dip store ] choose ; + [ kv:update-entry ] [ kv:add-entry ] choose ; ~~~ The last word is `kv:get`, which returns the contents of the