OSDN Git Service

Look up words in the dictionary.
authorsforman <sforman@hushmail.com>
Sat, 29 Jul 2023 19:35:47 +0000 (12:35 -0700)
committersforman <sforman@hushmail.com>
Sat, 29 Jul 2023 19:35:47 +0000 (12:35 -0700)
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?

implementations/Elm/src/Joy.elm

index 8b4d42f..267a54a 100644 (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)