add defs for select and small; cleaner joy-func.

This commit is contained in:
sforman 2023-10-13 07:42:22 -07:00
parent 205086714d
commit 68a85c915a
5 changed files with 141 additions and 192 deletions

File diff suppressed because one or more lines are too long

View File

@ -583,7 +583,6 @@ Concatinate two lists.
[flatten]
[fourth]
[getitem]
[remove]
[rest]
[reverse]
[rrest]
@ -591,7 +590,6 @@ Concatinate two lists.
[shift]
[shunt]
[size]
[sort]
[split_at]
[split_list]
[swaack]
@ -1099,7 +1097,6 @@ Note that only one "level" of lists is flattened. In the example above
[first_two]
[fourth]
[getitem]
[remove]
[rest]
[reverse]
[rrest]
@ -1107,7 +1104,6 @@ Note that only one "level" of lists is flattened. In the example above
[shift]
[shunt]
[size]
[sort]
[split_at]
[split_list]
[swaack]
@ -1283,7 +1279,6 @@ implementation-dependant.)
[first_two]
[flatten]
[fourth]
[remove]
[rest]
[reverse]
[rrest]
@ -1291,7 +1286,6 @@ implementation-dependant.)
[shift]
[shunt]
[size]
[sort]
[split_at]
[split_list]
[swaack]
@ -1374,22 +1368,6 @@ Greater-than comparison of two numbers.
------------------------------------------------------------------------
## help
Accepts a quoted symbol on the top of the stack and prints its
documentation.
[foo] help
----------------
### Discussion
Technically this is equivalent to `pop`, but it will only work if the
item on the top of the stack is a quoted symbol.
--------------
## --
See [pred](#pred).
@ -1402,16 +1380,6 @@ See [pred](#pred).
See [sub](#sub).
------------------------------------------------------------------------
## id
The identity function.
### Discussion
Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy.
------------------------------------------------------------------------
## ifte
@ -2338,6 +2306,7 @@ This comes from the original Joy stuff.
### Crosslinks
[quote-two]
[unit]
@ -2420,23 +2389,6 @@ See [mod](#mod).
See [mod](#mod).
------------------------------------------------------------------------
## remove
Expects an item on the stack and a quote under it and removes that item
from the the quote. The item is only removed once. If the list is empty
or the item isn't in the list then the list is unchanged.
[1 2 3 1] 1 remove
------------------------
[2 3 1]
### Definition
See the ["Remove Function" notebook](https://osdn.net/projects/joypy/scm/git/Thun/blobs/master/docs/notebooks/Remove-Function.ipynb).
------------------------------------------------------------------------
## rest
@ -2670,19 +2622,6 @@ and an error if it is not a list.
[null]
------------------------------------------------------------------------
## sort
Given a list return it sorted.
### Example
[4 2 5 7 1] sort
----------------------
[1 2 4 5 7]
------------------------------------------------------------------------
## spiral_next
@ -2854,23 +2793,6 @@ Take the [stack] and [uncons] the top item.
--------------------
1 2 3 3 [2 1]
------------------------------------------------------------------------
## stununcons
Take the [stack] and [uncons] the top two items.
### Example
1 2 3 stununcons
----------------------
1 2 3 3 2 [1]
### Crosslinks
[stuncons]
------------------------------------------------------------------------
## sub
@ -3170,13 +3092,6 @@ This is the inverse of [cons].
[cons]
------------------------------------------------------------------------
## unique
Given a list remove duplicate items.
------------------------------------------------------------------------
## unit
@ -3259,19 +3174,6 @@ stack.) The quoted programs are run with [nullary].
[and]
------------------------------------------------------------------------
## void
True if the form on TOS is void otherwise False.
### Discussion
A form is any Joy expression composed solely of lists.
This represents a binary Boolean logical formula in the arithmetic of the
"Laws of Form", see [The Markable Mark](http://www.markability.net/)
------------------------------------------------------------------------
## warranty
@ -3299,22 +3201,6 @@ and runs it [nullary].
[loop]
------------------------------------------------------------------------
## words
Print all the words in alphabetical order.
### Discussion
Mathematically this is a form of [id].
### Crosslinks
[help]
--------------------
## x
@ -3349,3 +3235,74 @@ from each list. The smallest list sets the length of the result list.
-------------------------
[[1 4] [2 5] [3 6]]
------------------------------------------------------------------------
## empty?
Expects a list on the stack and pushes `true` if it's empty and `false` otherwise.
It doesn't consume the list.
### Crosslinks
[null]
------------------------------------------------------------------------
## max-of-two
Expects two integers on the stack and removes the lesser of them, if they are equal just remove one.
------------------------------------------------------------------------
## min-of-two
Expects two integers on the stack and removes the greater of them, if they are equal just remove one.
------------------------------------------------------------------------
## quote-two
Take two items from the stack and put them into a new list.
joy? 1 2 3 4
1 2 3 4
joy? quote-two
1 2 [3 4]
### Crosslinks
[quoted]
------------------------------------------------------------------------
## uncons-two
Expect two non-empty lists on the stack and `uncons` the first item from each.
joy? [1 2] [3 4] uncons-two
1 3 [2] [4]
------------------------------------------------------------------------
## uncons-pair
Expect two non-empty lists on the stack and `uncons` the first item from each and put them in a new list.
joy? [1 2] [3 4] uncons-pair
[1 3] [2] [4]

View File

@ -99,8 +99,9 @@ run <{} infra
second rest first
shift uncons [swons] dip
shunt [swons] step
select [first] [second] branch
size [pop ++] step_zero
small dup null [rest null] [pop true] branch
small empty? [rest null] [pop true] branch
spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte
split_at [drop] [take] clop
split_list [take reverse] [drop] clop

View File

@ -1 +1 @@
(define (defs) (list "eq [false] [true] [false] cmp" "gt [true] [false] [false] cmp" "lt [false] [false] [true] cmp" "neq [true] [false] [true] cmp" "le [false] [true] [true] cmp" "ge [true] [true] [false] cmp" "? dup bool" "!- 0 >=" "++ 1 +" "-- 1 -" "<{} [] swap" "<<{} [] rollup" "abs dup 0 < [] [neg] branch" "anamorphism [pop []] swap [dip swons] genrec" "and nulco [nullary [false]] dip branch" "app1 grba infrst" "app2 [grba swap grba swap] dip [infrst] cons ii" "app3 3 appN" "appN [grabN] codi map reverse disenstacken" "at drop first" "average [sum] [size] cleave /" "b [i] dip i" "binary unary popd" "ccccons ccons ccons" "ccons cons cons" "choice [pop] [popd] branch" "clear [] swaack pop" "cleave fork popdd" "clop cleave popdd" "cmp [[>] swap] dipd [ifte] ccons [=] swons ifte" "codi cons dip" "codireco codi reco" "dinfrirst dip infrst" "dipd [dip] codi" "dipdd [dip] cons dipd" "dipddd [dipd] cons dipd" "disenstacken swaack pop" "divmod [/] [%] clop" "down_to_zero [0 >] [dup --] while" "drop [rest] times" "dupdd [dup] dipd" "dupd [dup] dip" "dupdipd dup dipd" "dupdip dupd dip" "enstacken stack [clear] dip" "first uncons pop" "first_two uncons first" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "getitem [rest] times first" "grabN <{} [cons] times" "grba [stack popd] dip" "ifte [nullary] dipd swap branch" "ii [dip] dupdip i" "infra swons swaack [i] dip swaack" "infrst infra first" "<< lshift" "lshift [2 *] times" "make_generator [codireco] ccons" "mod %" "modulus %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null _isnt_list bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "pick getitem" "pm [+] [-] clop" "popdd [pop] dipd" "popd [pop] dip" "popopdd [popop] dipd" "popopd [popop] dip" "popopop pop popop" "popop pop pop" "pow 1 roll> swap [*] cons times" "pred --" "product 1 swap [*] step" "quoted [unit] dip" "range [0 <=] [-- dup] anamorphism" "range_to_zero unit [down_to_zero] infra" "reco rest cons" "rest uncons popd" "reverse <{} shunt" "rolldown roll<" "roll< swapd swap" "roll> swap swapd" "rollup roll>" "rrest rest rest" ">> rshift" "rshift [2 /] times" "run <{} infra" "second rest first" "shift uncons [swons] dip" "shunt [swons] step" "size [pop ++] step_zero" "small dup null [rest null] [pop true] branch" "spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte" "split_at [drop] [take] clop" "split_list [take reverse] [drop] clop" "sqr dup mul" "stackd [stack] dip" "step_zero 0 roll> step" "stuncons stack uncons" "succ --" "sum [+] step_zero" "swapd [swap] dip" "swoncat swap concat" "swons swap cons" "tailrec [i] genrec" "take <<{} [shift] times pop" "ternary binary popd" "third rest second" "tuck dup swapd" "unary nullary popd" "uncons [first] dupdip rest" "unit [] cons" "unquoted [i] dip" "unstack [[] swaack] dip swoncat swaack pop" "unswons uncons swap" "while swap nulco dupdipd concat loop" "x dup i" "step [_step0] x" "_step0 _step1 [popopop] [_stept] branch" "_step1 [?] dipd roll<" "_stept [uncons] dipd [dupdipd] dip x" "times [_times0] x" "_times0 _times1 [popopop] [_timest] branch" "_times1 [dup 0 >] dipd roll<" "_timest [[--] dip dupdipd] dip x" "map [_map0] cons [[] [_map?] [_mape]] dip tailrec" "_map? pop bool not" "_mape popd reverse" "_map0 [_map1] dipd _map2" "_map1 stackd shift" "_map2 [infrst] cons dipd roll< swons" "_isnt_bool [false] [true] branch" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "_isnt_list [] swoncat" "zip [null] [pop] [uncons-pair] [i cons] genrec" "uncons-pair uncons-two [quote-two] dipd" "uncons-two [uncons] ii swapd" "quote-two unit cons" "empty? dup null" "max-of-two [>] [pop] [popd] ifte" "max empty? [uncons [max-of-two] step] [] branch"))
(define (defs) (list "eq [false] [true] [false] cmp" "gt [true] [false] [false] cmp" "lt [false] [false] [true] cmp" "neq [true] [false] [true] cmp" "le [false] [true] [true] cmp" "ge [true] [true] [false] cmp" "? dup bool" "!- 0 >=" "++ 1 +" "-- 1 -" "<{} [] swap" "<<{} [] rollup" "abs dup 0 < [] [neg] branch" "anamorphism [pop []] swap [dip swons] genrec" "and nulco [nullary [false]] dip branch" "app1 grba infrst" "app2 [grba swap grba swap] dip [infrst] cons ii" "app3 3 appN" "appN [grabN] codi map reverse disenstacken" "at drop first" "average [sum] [size] cleave /" "b [i] dip i" "binary unary popd" "ccccons ccons ccons" "ccons cons cons" "choice [pop] [popd] branch" "clear [] swaack pop" "cleave fork popdd" "clop cleave popdd" "cmp [[>] swap] dipd [ifte] ccons [=] swons ifte" "codi cons dip" "codireco codi reco" "dinfrirst dip infrst" "dipd [dip] codi" "dipdd [dip] cons dipd" "dipddd [dipd] cons dipd" "disenstacken swaack pop" "divmod [/] [%] clop" "down_to_zero [0 >] [dup --] while" "drop [rest] times" "dupdd [dup] dipd" "dupd [dup] dip" "dupdipd dup dipd" "dupdip dupd dip" "enstacken stack [clear] dip" "first uncons pop" "first_two uncons first" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "getitem [rest] times first" "grabN <{} [cons] times" "grba [stack popd] dip" "ifte [nullary] dipd swap branch" "ii [dip] dupdip i" "infra swons swaack [i] dip swaack" "infrst infra first" "<< lshift" "lshift [2 *] times" "make_generator [codireco] ccons" "mod %" "modulus %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null _isnt_list bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "pick getitem" "pm [+] [-] clop" "popdd [pop] dipd" "popd [pop] dip" "popopdd [popop] dipd" "popopd [popop] dip" "popopop pop popop" "popop pop pop" "pow 1 roll> swap [*] cons times" "pred --" "product 1 swap [*] step" "quoted [unit] dip" "range [0 <=] [-- dup] anamorphism" "range_to_zero unit [down_to_zero] infra" "reco rest cons" "rest uncons popd" "reverse <{} shunt" "rolldown roll<" "roll< swapd swap" "roll> swap swapd" "rollup roll>" "rrest rest rest" ">> rshift" "rshift [2 /] times" "run <{} infra" "second rest first" "shift uncons [swons] dip" "shunt [swons] step" "select [first] [second] branch" "size [pop ++] step_zero" "small dup null [rest null] [pop true] branch" "spiral_next [[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte" "split_at [drop] [take] clop" "split_list [take reverse] [drop] clop" "sqr dup mul" "stackd [stack] dip" "step_zero 0 roll> step" "stuncons stack uncons" "succ --" "sum [+] step_zero" "swapd [swap] dip" "swoncat swap concat" "swons swap cons" "tailrec [i] genrec" "take <<{} [shift] times pop" "ternary binary popd" "third rest second" "tuck dup swapd" "unary nullary popd" "uncons [first] dupdip rest" "unit [] cons" "unquoted [i] dip" "unstack [[] swaack] dip swoncat swaack pop" "unswons uncons swap" "while swap nulco dupdipd concat loop" "x dup i" "step [_step0] x" "_step0 _step1 [popopop] [_stept] branch" "_step1 [?] dipd roll<" "_stept [uncons] dipd [dupdipd] dip x" "times [_times0] x" "_times0 _times1 [popopop] [_timest] branch" "_times1 [dup 0 >] dipd roll<" "_timest [[--] dip dupdipd] dip x" "map [_map0] cons [[] [_map?] [_mape]] dip tailrec" "_map? pop bool not" "_mape popd reverse" "_map0 [_map1] dipd _map2" "_map1 stackd shift" "_map2 [infrst] cons dipd roll< swons" "_isnt_bool [false] [true] branch" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "_isnt_list [] swoncat" "zip [null] [pop] [uncons-pair] [i cons] genrec" "uncons-pair uncons-two [quote-two] dipd" "uncons-two [uncons] ii swapd" "quote-two unit cons" "empty? dup null" "max-of-two [>] [pop] [popd] ifte" "max [uncons [max-of-two] step] on-non-empty-list" "min-of-two [<] [pop] [popd] ifte" "min [uncons [min-of-two] step] on-non-empty-list" "on-non-empty-list [empty?] dip [first] branch"))

View File

@ -55,18 +55,18 @@
(define (joy-eval symbol stack expression dict)
(match symbol
((or "+" "add") ((joy-func +) stack expression dict))
((or "-" "sub") ((joy-func -) stack expression dict))
((or "*" "mul") ((joy-func *) stack expression dict))
((or "/" "div") ((joy-func quotient) stack expression dict)) ; but for negative divisor, no!?
((or "%" "mod") ((joy-func modulo) stack expression dict))
((or "+" "add") (joy-func + stack expression dict))
((or "-" "sub") (joy-func - stack expression dict))
((or "*" "mul") (joy-func * stack expression dict))
((or "/" "div") (joy-func quotient stack expression dict)) ; but for negative divisor, no!?
((or "%" "mod") (joy-func modulo stack expression dict))
("<" ((joy-func <) stack expression dict))
(">" ((joy-func >) stack expression dict))
("<=" ((joy-func <=) stack expression dict))
(">=" ((joy-func >=) stack expression dict))
("=" ((joy-func =) stack expression dict))
((or "<>" "!=") ((joy-func not-equal) stack expression dict))
((or "<" "lt") (joy-func < stack expression dict))
((or ">" "gt") (joy-func > stack expression dict))
((or "<=" "le") (joy-func <= stack expression dict))
((or ">=" "ge") (joy-func >= stack expression dict))
((or "=" "eq") (joy-func = stack expression dict))
((or "<>" "!=" "neq") (joy-func not-equal stack expression dict))
("bool" (joy-bool stack expression dict))
@ -76,8 +76,8 @@
("swaack" (values (cons (cdr stack) (car stack)) expression dict))
("swap" (values (cons (cadr stack) (cons (car stack) (cddr stack))) expression dict))
("concat" ((joy-func append) stack expression dict))
("cons" ((joy-func cons) stack expression dict))
("concat" (joy-func append stack expression dict))
("cons" (joy-func cons stack expression dict))
("first" (values (cons (caar stack) (cdr stack)) expression dict))
("rest" (values (cons (cdar stack) (cdr stack)) expression dict))
@ -92,9 +92,8 @@
(define (not-equal a b) (not (= a b)))
(define (joy-func op)
(lambda (stack expression dict)
(values (cons (op (cadr stack) (car stack)) (cddr stack)) expression dict)))
(define (joy-func op stack expression dict)
(values (cons (op (cadr stack) (car stack)) (cddr stack)) expression dict))
(define (joy-bool stack expression dict)