diff --git a/docs/html/FuncRef.html b/docs/html/FuncRef.html index 68cca1b..856e805 100644 --- a/docs/html/FuncRef.html +++ b/docs/html/FuncRef.html @@ -8,7 +8,7 @@ ---------- n >= 0 true
Return a Boolean value indicating if a number is greater than or equal to -zero.
... b a <{}
+zero. ... b a <{}
-----------------
... [] b a
Tuck an empty list just under the first two items on the stack.
... a <{}
@@ -113,7 +113,7 @@ empty list is false and all other lists are true.<
T
This is one of the fundamental operations (although it can be defined in terms of [choice] as above). The more common "if..then..else" construct -[ifte] adds a predicate function that is evaluated [nullary].
a b c d [...] ccccons
+[ifte] adds a predicate function that is evaluated [nullary]. a b c d [...] ccccons
---------------------------
[a b c d ...]
@@ -129,7 +129,7 @@ terms of [choice] as above). The more common "if..then..else" construct
a b true choice
---------------------
b
-It's a matter of taste whether you implement this in terms of [branch] or +
It's a matter of taste whether you implement this in terms of [branch] or the other way around.
combinator
Run two programs in parallel, consuming one additional item, and put their results on the stack.
... x [A] [B] cleave
@@ -206,7 +206,7 @@ expressions, e.g.:
------------------
[a ...]
Cons is a venerable old function from Lisp. -Its inverse operation is [uncons].
combinator built-in
The dip combinator expects a quoted program on the stack and below it
+Its inverse operation is [uncons].
combinator built-in
The dip combinator expects a quoted program on the stack and below it
some item, it hoists the item into the expression and runs the program
on the rest of the stack.
... x [Q] . dip
@@ -228,7 +228,7 @@ pending expression (not counting modifications to the dictionary.) ... y x [Q] . dipd
-------------------------
... . Q y x
-See [dip].
combinator
Like [dip] but expects three items. :
... z y x [Q] . dipdd
-----------------------------
... . Q z y x
@@ -303,7 +303,7 @@ them with a Boolean value.
[a ...]
--------------
a
-
Replace a list with its first two items.
+Replace a list with its first two items.
[a b ...] first_two
-------------------------
a b
@@ -366,15 +366,15 @@ Tail recursive functions are those where R2 is the i c
P == [I] [T] [R] tailrec
== [I] [T] [R [P] i] ifte
== [I] [T] [R P] ifte
-Expects an integer and a quote on the stack and returns the item at the +
Expects an integer and a quote on the stack and returns the item at the nth position in the quote counting from 0.
[a b c d] 2 getitem
-------------------------
c
-If the number isn't a valid index into the quote getitem will cause
+
If the number isn't a valid index into the quote getitem will cause
some sort of problem (the exact nature of which is
-implementation-dependant.)
Expect a number on the top of the stack and [cons] that many items from under it onto a new list.
+implementation-dependant.)Expect a number on the top of the stack and [cons] that many items from under it onto a new list.
a b c d e 3 grabN
-----------------------
@@ -400,7 +400,7 @@ item on the top of the stack is a quoted symbol.This is a fundamental combinator. It is used in all kinds of places. For
-example, the [x] combinator can be defined as dup i.
The identity function.
Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy.
combinator
If-Then-Else combinator, a common and convenient specialization of [branch].
+example, the [x] combinator can be defined asdup i.The identity function.
Does nothing. It's kind of a mathematical thing, but it occasionally comes in handy.
combinator
If-Then-Else combinator, a common and convenient specialization of [branch].
[if] [then] [else] ifte
---------------------------------------
[if] nullary [else] [then] branch
@@ -427,7 +427,7 @@ top item, then again with the top item.
1 9
1 2 3 4 [+] app2
----------------------
- 1 2 5 6combinator
Accept a quoted program and a list on the stack and run the program with + 1 2 5 6
combinator
Accept a quoted program and a list on the stack and run the program with the list as its stack. Does not affect the stack (below the list.)
... x y z [a b c] [Q] infra
---------------------------------
@@ -524,7 +524,7 @@ parallelism combinator due to the "pure" nature of the language. a b mod
-------------
(a%b)
-built-in
Multiply two numbers.
a b mul
-------------
(a×b)
@@ -552,7 +552,7 @@ stack, replacing them with a Boolean value.
[[F] nullary]
Helper function for [or] and [and].
True if the item on the top of the stack is an empty list, false if it's a list but not empty, -and an error if it's not a list.
combinator
Run a quoted program without using any stack values and leave the first +and an error if it's not a list.
combinator
Run a quoted program without using any stack values and leave the first item of the result on the stack.
... [P] nullary
---------------------
@@ -594,18 +594,18 @@ rest of the stack.)
-------------------------------
5 7 [12 -2 35 0 5]
A specialization of [map] that runs a list of functions in parallel (if -the underlying [map] function is so implemented, of course.)
Plus or minus. Replace two numbers with their sum and difference.
+the underlying [map] function is so implemented, of course.)Plus or minus. Replace two numbers with their sum and difference.
a b pm
-----------------
(a+b) (a-b)
[pop] the second item down on the stack.
+[pop] the second item down on the stack.
a b popd
--------------
b
-[pop] the third item on the stack.
+[pop] the third item on the stack.
a b c popdd
-----------------
b c
@@ -632,7 +632,7 @@ power. (n is on the top of the stack.)
2 [2 3 4 5 6 7 8 9] [pow] map
-----------------------------------
2 [4 8 16 32 64 128 256 512]
-
combinator
From the "Overview of the language JOY"
The primrec combinator expects two quoted programs in addition to a data parameter. For an integer data parameter it works like this: If @@ -701,7 +701,7 @@ or the item isn't in the list then the list is unchanged.
See the "Remove Function" notebook.
Reverse the list on the top of the stack.
+Reverse the list on the top of the stack.
[1 2 3] reverse
---------------------
@@ -821,7 +821,7 @@ complement to the "destructive" pair [enstacken] and [disenstacken]. a b sub
-------------
(a-b)
-combinator
Given a quoted sequence of numbers return the sum.
[1 2 3 4 5] sum
---------------------
@@ -841,7 +841,7 @@ definition of [infra]. a b c swapd
-----------------
b a c
-Like [cons] but [swap] the item and list.
+Like [cons] but [swap] the item and list.
[...] a swons
-------------------
[a ...]
@@ -890,7 +890,7 @@ program n times.
This is a common pattern in Joy. You accept some parameters from the
stack which typically include qouted programs and use them to build
another program which does the actual work. This is kind of like macros
-in Lisp, or preprocessor directives in C.[dup] the item on the top of the stack under the second item on the +in Lisp, or preprocessor directives in C.
[dup] the item on the top of the stack under the second item on the stack.
a b tuck
--------------
@@ -907,10 +907,10 @@ the list. You cannot uncons an item from an empty list.
[a ...] uncons
--------------------
a [...]
-
This is the inverse of [cons].
Given a list remove duplicate items.
Given a list remove duplicate items.
combinator
Unquote (using [i]) the list that is second on the stack.
1 2 [3 4] 5 unquoted
--------------------------
@@ -949,8 +949,8 @@ from each list. The smallest list sets the length of the result list.
Example
[1 2 3] [4 5 6] zip
-------------------------
- [[4 1] [5 2] [6 3]]
-
combinator
Short-circuiting Boolean OR
Accept two quoted programs, run the first and expect a Boolean value, if + [[1 4] [2 5] [3 6]] +
combinator
Short-circuiting Boolean OR
Accept two quoted programs, run the first and expect a Boolean value, if
it’s false pop it and run the second program (which should also return a
Boolean value) otherwise pop the second program (leaving true on the
stack.)
diff --git a/docs/html/notebooks/DeriveZip.html b/docs/html/notebooks/DeriveZip.html
new file mode 100644
index 0000000..eb7ba02
--- /dev/null
+++ b/docs/html/notebooks/DeriveZip.html
@@ -0,0 +1,56 @@
+
+
+
Let's derive zip.
[a b c ...] [e f g ...] zip
+---------------------------------
+ [[a e] [b f] [c g] ...]
+
+It's a genrec:
zip == [null] [popop []] [R0] [R1] genrec
+
+If the top list is empty, pop both lists and put a new empty list...
+Hmm...
+zip == [null] [pop] [R0] [R1] genrec
+
+We will assume that both lists are the same size, so if the top list is empty the second list shall be too, and we can reuse it to store our pairs.
+Now then, we have two non-empty lists:
+[a b c ...] [e f g ...] R0 [zip] R1
+
+Let's imagine a function shift-pair:
[a ...] [e ...] shift-pair
+--------------------------------
+ [a e] [...] [...]
+
+I'm going to defer derivation of that for now.
+[a b c ...] [e f g ...] shift-pair [zip] R1
+
+[a e] [b c ...] [f g ...] [zip] R1
+
+And so R1 is i cons (it's a list builder.)
zip == [null] [pop] [shift-pair] [i cons] genrec
+
+And now:
+shift-pair == uncons-two [quote-two] dipd
+
+w/
+uncons-two == [uncons] ii swapd
+quote-two == unit cons
+
+[zip [null] [pop] [shift-pair] [i cons] genrec] inscribe
+[shift-pair uncons-two [quote-two] dipd] inscribe
+[uncons-two [uncons] ii swapd] inscribe
+[quote-two unit cons] inscribe
+
+
+
+
diff --git a/docs/reference/Function-Reference.md b/docs/reference/Function-Reference.md
index b5a3714..2d4da7f 100644
--- a/docs/reference/Function-Reference.md
+++ b/docs/reference/Function-Reference.md
@@ -3362,5 +3362,5 @@ from each list. The smallest list sets the length of the result list.
[1 2 3] [4 5 6] zip
-------------------------
- [[4 1] [5 2] [6 3]]
+ [[1 4] [2 5] [3 6]]
diff --git a/docs/source/notebooks/DeriveZip.md b/docs/source/notebooks/DeriveZip.md
new file mode 100644
index 0000000..b8fbe57
--- /dev/null
+++ b/docs/source/notebooks/DeriveZip.md
@@ -0,0 +1,54 @@
+# Zip
+
+Let's derive `zip`.
+
+ [a b c ...] [e f g ...] zip
+ ---------------------------------
+ [[a e] [b f] [c g] ...]
+
+It's a `genrec`:
+
+ zip == [null] [popop []] [R0] [R1] genrec
+
+If the top list is empty, pop both lists and put a new empty list...
+
+Hmm...
+
+ zip == [null] [pop] [R0] [R1] genrec
+
+We will assume that both lists are the same size, so if the top list is empty the second list shall be too, and we can reuse it to store our pairs.
+
+Now then, we have two non-empty lists:
+
+ [a b c ...] [e f g ...] R0 [zip] R1
+
+Let's imagine a function `shift-pair`:
+
+ [a ...] [e ...] shift-pair
+ --------------------------------
+ [a e] [...] [...]
+
+I'm going to defer derivation of that for now.
+
+ [a b c ...] [e f g ...] shift-pair [zip] R1
+
+ [a e] [b c ...] [f g ...] [zip] R1
+
+And so `R1` is `i cons` (it's a list builder.)
+
+ zip == [null] [pop] [shift-pair] [i cons] genrec
+
+And now:
+
+ shift-pair == uncons-two [quote-two] dipd
+
+w/
+
+ uncons-two == [uncons] ii swapd
+ quote-two == unit cons
+
+ [zip [null] [pop] [shift-pair] [i cons] genrec] inscribe
+ [shift-pair uncons-two [quote-two] dipd] inscribe
+ [uncons-two [uncons] ii swapd] inscribe
+ [quote-two unit cons] inscribe
+
diff --git a/implementations/scheme-chicken/defs.scm b/implementations/scheme-chicken/defs.scm
index 0c8816b..eb9c923 100644
--- a/implementations/scheme-chicken/defs.scm
+++ b/implementations/scheme-chicken/defs.scm
@@ -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" "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" "flatten <{} [concat] step" "fork [i] app2" "fourth rest third" "gcd true [tuck mod dup 0 >] loop pop" "genrec [[genrec] ccccons] nullary swons concat ifte" "grabN <{} [cons] times" "grba [stack popd] dip" "hypot [sqr] ii + sqrt" "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 %" "neg 0 swap -" "not [true] [false] branch" "nulco [nullary] cons" "nullary [stack] dinfrirst" "null [] swap concat bool not" "of swap at" "or nulco [nullary] dip [true] branch" "over [dup] dip swap" "pam [i] map" "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" "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" "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 not not" "_isnt_two_bools [_isnt_bool] ii" "_\\/_ [_isnt_bool] [not] branch" "/\\ _isnt_two_bools [pop false] [] branch" "\\/ _isnt_two_bools [] [pop true] branch" "xor [] [not] branch"))
\ No newline at end of file
+(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" "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" "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 %" "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" "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" "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" "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] [shift-pair] [i cons] genrec" "shift-pair uncons-two [quote-two] dipd" "uncons-two [uncons] ii swapd" "quote-two unit cons"))
\ No newline at end of file