This commit is contained in:
sforman 2023-07-29 09:17:27 -07:00
parent 70c5223319
commit eb8b282bc2
1 changed files with 12 additions and 0 deletions

View File

@ -44,6 +44,7 @@ joy_eval symbol stack expression =
"xor" -> joy_binary_math_op (Bitwise.xor) stack expression "xor" -> joy_binary_math_op (Bitwise.xor) stack expression
"clear" -> Ok ([], expression) "clear" -> Ok ([], expression)
"concat" -> joy_concat stack expression "concat" -> joy_concat stack expression
"cons" -> joy_cons stack expression
_ -> Err ("Unknown word: " ++ symbol) _ -> Err ("Unknown word: " ++ symbol)
@ -68,6 +69,17 @@ joy_concat stack expression =
Err msg -> Err msg Err msg -> Err msg
joy_cons : JList -> JList -> Result String (JList, JList)
joy_cons stack expression =
case pop_list(stack) of
Ok (a, s0) ->
case pop_any(s0) of
Ok (b, s1) ->
Ok ((push_list (b :: a) s1), expression)
Err msg -> Err msg
Err msg -> Err msg
push_int : Int -> JList -> JList push_int : Int -> JList -> JList
push_int i stack = (JoyInt i) :: stack push_int i stack = (JoyInt i) :: stack