From edfd7c526f16f5c7db34bf0da8076f81ab0373b2 Mon Sep 17 00:00:00 2001 From: sforman Date: Sat, 29 Jul 2023 12:35:47 -0700 Subject: [PATCH] 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? --- implementations/Elm/src/Joy.elm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/implementations/Elm/src/Joy.elm b/implementations/Elm/src/Joy.elm index 8b4d42f..267a54a 100644 --- a/implementations/Elm/src/Joy.elm +++ b/implementations/Elm/src/Joy.elm @@ -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) -- 2.11.0