From 00f4bfcacdfc1df214975207451b63bb4b891a65 Mon Sep 17 00:00:00 2001 From: sforman Date: Sat, 12 Aug 2023 08:04:21 -0700 Subject: [PATCH] Math ops, definitions for left- and right-shift. --- implementations/Nim/defs.txt | 15 +++++++++++---- implementations/defs.txt | 2 ++ implementations/scheme-chicken/joy.scm | 7 +++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/implementations/Nim/defs.txt b/implementations/Nim/defs.txt index c211788..6d0ed4d 100644 --- a/implementations/Nim/defs.txt +++ b/implementations/Nim/defs.txt @@ -12,6 +12,8 @@ or nulco [nullary] dip [true] branch !- 0 >= <{} [] swap <<{} [] rollup +<< lshift +>> rshift abs dup 0 < [] [neg] branch anamorphism [pop []] swap [dip swons] genrec app1 grba infrst @@ -54,14 +56,16 @@ ifte [nullary] dipd swap branch ii [dip] dupdip i infra swons swaack [i] dip swaack infrst infra first +lshift [2 *] times make_generator [codireco] ccons mod % neg 0 swap - not [true] [false] branch nulco [nullary] cons -null [] concat bool not +null [] swap concat bool not nullary [stack] dinfrirst of swap at +over [dup] dip swap pam [i] map pm [+] [-] clop popd [pop] dip @@ -82,6 +86,7 @@ roll< swapd swap rollup roll> rolldown roll< rrest rest rest +rshift [2 /] times run <{} infra second rest first shift uncons [swons] dip @@ -126,6 +131,8 @@ _mape popd reverse _map0 [_map1] dipd _map2 _map1 stackd shift _map2 [infrst] cons dipd roll< swons -_\/_ [not not] [not] branch -/\ [not not] ii [pop false] [] branch -\/ [not not] ii [] [pop true] branch \ No newline at end of file +_isnt_bool not not +_isnt_two_bools [_isnt_bool] ii +_\/_ [_isnt_bool] [not] branch +/\ _isnt_two_bools [pop false] [] branch +\/ _isnt_two_bools [] [pop true] branch diff --git a/implementations/defs.txt b/implementations/defs.txt index f85e92a..6d0ed4d 100644 --- a/implementations/defs.txt +++ b/implementations/defs.txt @@ -56,6 +56,7 @@ ifte [nullary] dipd swap branch ii [dip] dupdip i infra swons swaack [i] dip swaack infrst infra first +lshift [2 *] times make_generator [codireco] ccons mod % neg 0 swap - @@ -85,6 +86,7 @@ roll< swapd swap rollup roll> rolldown roll< rrest rest rest +rshift [2 /] times run <{} infra second rest first shift uncons [swons] dip diff --git a/implementations/scheme-chicken/joy.scm b/implementations/scheme-chicken/joy.scm index 4175385..26cf920 100644 --- a/implementations/scheme-chicken/joy.scm +++ b/implementations/scheme-chicken/joy.scm @@ -48,7 +48,14 @@ ((is-it? "+") ((joy-func +) stack expression dict)) ((is-it? "-") ((joy-func -) stack expression dict)) ((is-it? "*") ((joy-func *) stack expression dict)) + ((is-it? "/") ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!? + ((is-it? "%") ((joy-func modulo) stack expression dict)) + + ((is-it? "add") ((joy-func +) stack expression dict)) + ((is-it? "sub") ((joy-func -) stack expression dict)) ((is-it? "mul") ((joy-func *) stack expression dict)) + ((is-it? "div") ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!? + ((is-it? "mod") ((joy-func modulo) stack expression dict)) ((is-it? "<") ((joy-func <) stack expression dict)) ((is-it? ">") ((joy-func >) stack expression dict))