This commit is contained in:
sforman 2023-07-29 09:22:26 -07:00
parent eb8b282bc2
commit b50be3b64b
1 changed files with 7 additions and 0 deletions

View File

@ -45,6 +45,7 @@ joy_eval symbol stack expression =
"clear" -> Ok ([], expression)
"concat" -> joy_concat stack expression
"cons" -> joy_cons stack expression
"dup" -> joy_dup stack expression
_ -> Err ("Unknown word: " ++ symbol)
@ -80,6 +81,12 @@ joy_cons stack expression =
Err msg -> Err msg
joy_dup : JList -> JList -> Result String (JList, JList)
joy_dup stack expression =
case pop_any(stack) of
Ok (a, s0) -> Ok ((a :: stack), expression)
Err msg -> Err msg
push_int : Int -> JList -> JList
push_int i stack = (JoyInt i) :: stack