Look up words in the dictionary.

If they are not built-in, which means you can't "shadow" built-ins with
"inscribe", which may or may not turn out to be what we want?
This commit is contained in:
sforman 2023-07-29 12:35:47 -07:00
parent 4acdec71ed
commit edfd7c526f
1 changed files with 6 additions and 2 deletions

View File

@ -1,7 +1,7 @@
module Joy exposing (doit, JoyDict)
import Bitwise
import Dict exposing (Dict)
import Dict exposing (Dict, get)
import Result exposing (andThen)
import String exposing (replace, words)
@ -42,7 +42,11 @@ joy_eval symbol stack expression dict =
Err msg ->
if "Unknown word." == msg then
-- Look up word in dictionary.
Err ("Unknown word: " ++ symbol)
case get symbol dict of
Just definition ->
Ok (stack, definition ++ expression, dict)
Nothing ->
Err ("Unknown word: " ++ symbol)
else
Err msg
Ok (stack0, expression0) -> Ok (stack0, expression0, dict)