diff --git a/src/Main.elm b/src/Main.elm index 4e05b5d..0fcda08 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -166,6 +166,30 @@ parseMove = succeed Move initialScope : Scope initialScope = Child End Dict.empty Dict.empty +setScopeFunction : String -> Function -> Scope -> Scope +setScopeFunction s f scope = case scope of + End -> setScopeFunction s f initialScope + Child p fs vs -> Child p (Dict.insert s f fs) vs + +setScopeVariable : String -> Int -> Scope -> Scope +setScopeVariable s v scope = case scope of + End -> setScopeVariable s v initialScope + Child p fs vs -> Child p fs (Dict.insert s v vs) + +scopeFunction : String -> Scope -> Maybe Function +scopeFunction s scope = case scope of + End -> Nothing + Child p fs _ -> case Dict.get s fs of + Just f -> Just f + Nothing -> scopeFunction s p + +scopeVariable : String -> Scope -> Maybe Int +scopeVariable s scope = case scope of + End -> Nothing + Child p _ vs -> case Dict.get s vs of + Just i -> Just i + Nothing -> scopeVariable s p + initialState : State initialState = { penMode = Up @@ -214,30 +238,6 @@ downScope state = in Ok ((), { state | scope = newScope }) -setScopeFunction : String -> Function -> Scope -> Scope -setScopeFunction s f scope = case scope of - End -> setScopeFunction s f initialScope - Child p fs vs -> Child p (Dict.insert s f fs) vs - -setScopeVariable : String -> Int -> Scope -> Scope -setScopeVariable s v scope = case scope of - End -> setScopeVariable s v initialScope - Child p fs vs -> Child p fs (Dict.insert s v vs) - -scopeFunction : String -> Scope -> Maybe Function -scopeFunction s scope = case scope of - End -> Nothing - Child p fs _ -> case Dict.get s fs of - Just f -> Just f - Nothing -> scopeFunction s p - -scopeVariable : String -> Scope -> Maybe Int -scopeVariable s scope = case scope of - End -> Nothing - Child p _ vs -> case Dict.get s vs of - Just i -> Just i - Nothing -> scopeVariable s p - lookupFunction : String -> Step Function lookupFunction s state = case scopeFunction s state.scope of Just f -> Ok (f, state)