diff --git a/docs/MAKE b/docs/MAKE index d5d1faa..10c50bb 100644 --- a/docs/MAKE +++ b/docs/MAKE @@ -1,7 +1,8 @@ python build_index.py ./source/index.md > ./html/index.html -python build_index.py ./source/Thun.md > html/Thun.html +python build_index.py ./source/Thun.md > ./html/Thun.html python build_index.py ./source/notebooks/BigNums.md > ./html/notebooks/BigInts.html python build_index.py ./source/notebooks/Generator_Programs.md > ./html/notebooks/Generator_Programs.html (cd ../implementations/Elm/ ; make) cp -f ../implementations/Elm/demo/Joy.js ./html/Joy.js +(cd ../reference/ ; make) diff --git a/docs/html/FuncRef.html b/docs/html/FuncRef.html index 5541ee7..ad347b4 100644 --- a/docs/html/FuncRef.html +++ b/docs/html/FuncRef.html @@ -1,4 +1,4 @@ -
Version -10.0.0
Each function, combinator, or definition should be documented here.
Not negative.
+Version -10.0.0
Each function, combinator, or definition should be documented here.
Not negative.
n !-
----------- n < 0
false
@@ -7,34 +7,15 @@
n !-
---------- n >= 0
true
-combinator
Short-circuiting Boolean AND
-Accept two quoted programs, run the first and expect a Boolean value, if
-it's true pop it and run the second program (which should also return a
-Boolean value) otherwise pop the second program (leaving false on the
-stack.)
[A] [B] &&
----------------- true
- B
-
-
- [A] [B] &&
----------------- false
- false
-
-nulco [nullary [false]] dip branch
-
-TODO: this is derived in one of the notebooks I think, look it up and -link to it, or copy the content here.
... b a <{}
+Return a Boolean value indicating if a number is greater than or equal to +zero.
... b a <{}
-----------------
... [] b a
-[] rollup
... a <{}
+Tuck an empty list just under the first two items on the stack.
... a <{}
----------------
... [] a
-[] swap
Is the item on the top of the stack "truthy"?
Add two numbers together: a + b.
combinator
Build a list of values from a generator program G and a stopping
+
Tuck an empty list just under the first item on the stack.
Is the item on the top of the stack "truthy"?
You often want to test the truth value of an item on the stack without +consuming the item.
combinator
Build a list of values from a generator program G and a stopping
predicate P.
[P] [G] anamorphism
-----------------------------------------
@@ -42,36 +23,60 @@ predicate P.
The range function generates a list of the integers from 0 to n - 1:
[0 <=] [-- dup] anamorphism
+
-[0 <=] [-- dup] anamorphism
-
combinator
"apply one"
+joy? 5
+5
+joy? [0 <=] [-- dup]
+5 [0 <=] [-- dup]
+joy? anamorphism
+[4 3 2 1 0]
+ +Note that the last value generated (0) is at the bottom of the list. +See the Recursion Combinators notebook.
combinator
Short-circuiting Boolean AND
+Accept two quoted programs, run the first and expect a Boolean value, if
+it's true pop it and run the second program (which should also return a
+Boolean value) otherwise pop the second program (leaving false on the
+stack.) The quoted programs are run with [nullary].
[A] [B] and
+----------------- A -> true
+ B
+
+
+ [A] [B] and
+----------------- A -> false
+ false
+
+TODO: this is derived in one of the notebooks I think, look it up and +link to it, or copy the content here.
combinator
"apply one"
Given a quoted program on TOS and anything as the second stack item run -the program without disturbing the stack and replace the two args with +the program without disturbing the rest of the stack and replace the two args with the first result of the program.
... x [Q] app1
---------------------------------
... [x ...] [Q] infra first
-This is the same effect as the unary combinator.
combinator
Just a specialization of nullary really. Its parallelizable cousins
+are more useful.
combinator
Like app1 with two items.
... y x [Q] . app2
-----------------------------------
... [y ...] [Q] . infra first
[x ...] [Q] infra first
-Unlike app1, which is essentially an alias for unary, +this function is not the same as binary. Instead of running one program using exactly two items from the stack and pushing one -result (as [binary](#binary) does) this function takes two items from the +result (as binary does) this function takes two items from the stack and runs the program twice, separately for each of the items, then puts both results onto the stack. This is not currently implemented as parallel processes but it can (and -should) be done.
combinator
Like [app1] with three items.
... z y x [Q] . app3
-----------------------------------
... [z ...] [Q] . infra first
[y ...] [Q] infra first
[x ...] [Q] infra first
-combinator
Like [app1] with any number of items.
... xN ... x2 x1 x0 [Q] n . appN
--------------------------------------
... [xN ...] [Q] . infra first
@@ -79,26 +84,26 @@ should) be done.Compute the average of a list of numbers. +
This function takes a quoted function Q and an integer and runs the
+function that many times on that many stack items. See also [app2].
Compute the average of a list of numbers. (Currently broken until I can figure out what to do about "numeric tower" -in Thun.)
Theoretically this function would compute the sum and the size in two separate threads, then divide. This works but a compiled version would probably do better to sum and count the list once, in one thread, eh? As an exercise in Functional Programming in Joy it would be fun to convert this into a catamorphism. -See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
combinator
Run two quoted programs
[P] [Q] b
---------------
P Q
-combinator
Run a quoted program using exactly two stack values and leave the first +
This combinator may seem trivial but it comes in handy.
combinator
Run a quoted program using exactly two stack values and leave the first item of the result on the stack.
... y x [P] binary
-----------------------
... a
-Convert the item on the top of the stack to a Boolean value.
combinator built-in
Use a Boolean value to select and run one of two quoted programs.
+Runs any other quoted function and returns its first result while +consuming exactly two items from the stack.
Convert the item on the top of the stack to a Boolean value.
For integers 0 is false and any other number is true; for lists the
+empty list is false and all other lists are true.
combinator built-in
Use a Boolean value to select and run one of two quoted programs.
false [F] [T] branch
--------------------------
F
@@ -106,17 +111,17 @@ empty list is `false` and all other lists are `true`.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 ...]
-Do [cons] four times.
a b [...] ccons
---------------------
[a b ...]
-Do [cons] two times.
Use a Boolean value to select one of two items.
+Do [cons] two times.
Use a Boolean value to select one of two items.
a b false choice
----------------------
a
@@ -124,8 +129,8 @@ terms of [choice] as above). The more common "if..then..else" construct
a b true choice
---------------------
b
-combinator
Run two programs in parallel, consuming one additional item, and put their +
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
------------------------
@@ -139,14 +144,14 @@ results on the stack.
1 2 3 [+] [-] cleave
--------------------------
1 2 5 -1
-
combinator
Run two programs in parallel, consuming two additional items, and put their results on the stack.
+One of a handful of useful parallel combinators.
combinator
Run two programs in parallel, consuming two additional items, and put their results on the stack.
... x y [A] [B] clop
--------------------------
... a b
-Like [cleave] but consumes an additional item from the stack. 1 2 3 4 [+] [-] clop -------------------------- - 1 2 7 -1
combinator
Take two values and three quoted programs on the stack and run one of the three depending on the results of comparing the two values.
a b [G] [E] [L] cmp
------------------------- a > b
@@ -159,23 +164,23 @@ of the three depending on the results of comparing the two values.
a b [G] [E] [L] cmp
------------------------- a < b
L
-This is useful sometimes, and you can [dup] or [dupd] with two quoted programs to handle the cases when you just want to deal with [<=] or [>=] and not all three possibilities, e.g.: [G] [EL] dup cmp [GE] [L] dupd cmp Or even: - [GL] [E] over cmp
combinator
Take a quoted program from the stack, [cons] the next item onto it, then + [GL] [E] over cmp
combinator
Take a quoted program from the stack, [cons] the next item onto it, then [dip] the whole thing under what was the third item on the stack.
a b [F] . codi
--------------------
b . F a
-combinator
This is part of the [make_generator] function. You would not use this -combinator directly.
This is one of those weirdly specific functions that turns out to be +useful in a few places.
combinator
This is part of the [make_generator] function. You would not use this +combinator directly.
See [make_generator] and the
+"Using x to Generate Values" notebook
as well as
-[Recursion Theory and Joy](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html) by Manfred von Thun.
Concatinate two lists.
+Recursion Theory and Joy by Manfred von Thun.built-in
Concatinate two lists.
[a b c] [d e f] concat
----------------------------
[a b c d e f]
@@ -192,66 +197,66 @@ followed by the function expression to run if that predicate returns
[Default]
]
cond
-It works by rewriting into a chain of nested [ifte]{.title-ref} expressions, e.g.: [[[B0] T0] [[B1] T1] [D]] cond ----------------------------------------- - [B0] [T0] [[B1] [T1] [D] ifte] ifte
built-in
Given an item and a list, append the item to the list to make a new list.
+ [B0] [T0] [[B1] [T1] [D] ifte] iftebuilt-in
Given an item and a list, append the item to the list to make a new list.
a [...] cons
------------------
[a ...]
-combinator built-in
The dip combinator expects a quoted program on the stack and below it
+
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
some item, it hoists the item into the expression and runs the program
on the rest of the stack.
... x [Q] . dip
---------------------
... . Q x
-This along with [infra] are enough to update any datastructure.
+See the "Traversing Datastructures with Zippers" notebook.
+Note that the item that was on the top of the stack (x in the example above)
will not be treated specially by the interpreter when it is reached
again. This is something of a footgun. My advice is to avoid putting
bare unquoted symbols onto the stack, but then you can't use symbols as
-"atoms" and also use `dip` and `infra` to operate on compound
+"atoms" and also use dip and infra to operate on compound
datastructures with atoms in them. This is a kind of side-effect of the
-Continuation-Passing Style. The `dip` combinator could "set aside" the
-item and replace it after running `Q` but that means that there is an
-"extra space" where the item resides while `Q` runs. One of the nice
+Continuation-Passing Style. The dip combinator could "set aside" the
+item and replace it after running Q but that means that there is an
+"extra space" where the item resides while Q runs. One of the nice
things about CPS is that the whole state is recorded in the stack and
-pending expression (not counting modifications to the dictionary.)
combinator
Like [dip] but expects two items.
+pending expression (not counting modifications to the dictionary.)combinator
Like [dip] but expects two items.
... y x [Q] . dipd
-------------------------
... . Q y x
-combinator
Like [dip] but expects three items. :
... z y x [Q] . dip
-----------------------------
... . Q z y x
-The disenstacken function expects a list on top of the stack and makes
+
See [dip].
The disenstacken function expects a list on top of the stack and makes
that the stack discarding the rest of the stack.
1 2 3 [4 5 6] disenstacken
--------------------------------
6 5 4
-Note that the order of the list is not changed, it just looks that way because the stack is printed with the top on the right while lists are -printed with the top or head on the left.
x y divmod
+printed with the top or head on the left. x y divmod
------------------
q r
(x/y) (x%y)
-Invariant: qy + r = x.
Given a number greater than zero put all the Natural numbers (including +
Invariant: qy + r = x.
Given a number greater than zero put all the Natural numbers (including zero) less than that onto the stack.
3 down_to_zero
--------------------
3 2 1 0
-Expects an integer and a quote on the stack and returns the quote with n +
Expects an integer and a quote on the stack and returns the quote with n items removed off the top.
[a b c d] 2 drop
----------------------
[c d]
-built-in
"Dup"licate the top item on the stack.
a dup
-----------
a a
@@ -259,11 +264,11 @@ items removed off the top.
a b dupd
--------------
a a b
-
[dup] the third item down on the stack.
a b c dupdd
-----------------
a a b c
-combinator
Apply a function F and [dup] the item under it on the stack.
a [F] dupdip
------------------
a F a
@@ -275,26 +280,26 @@ a [F] [dup] dip dip
a dup [F] dip
a a [F] dip
a F a
-combinator
Run a copy of program F under the next item down on the stack.
A very common and useful combinator.
combinator
Run a copy of program F under the next item down on the stack.
a [F] dupdipd
-------------------
F a [F]
-Put the stack onto the stack replacing the contents of the stack.
+Put the stack onto the stack replacing the contents of the stack.
... a b c enstacken
-------------------------
[c b a ...]
-Compare the two items on the top of the stack for equality and replace +
This is a destructive version of [stack]. See the note under +[disenstacken] about the apparent but illusory reversal of the stack.
built-in
Compare the two items on the top of the stack for equality and replace them with a Boolean value.
a b eq
-------------
Boolean
(a = b)
-Replace a list with its first two items.
+Replace a list with its first two items.
[a b ...] first_two
-------------------------
a b
@@ -303,107 +308,109 @@ them with a Boolean value.
[[1 2] [3 [4] 5] [6 7]] flatten
-------------------------------------
[1 2 3 [4] 5 6 7]
-
Return the largest integer \<= x.
I don't know why this is called "floor" div, I think it rounds its +
Note that only one "level" of lists is flattened. In the example above
+[4] is not unquoted.
Return the largest integer \<= x.
This function doesn't make sense (yet) to have because there are (as yet) +only integers in the system.
I don't know why this is called "floor" div, I think it rounds its result down (not towards zero or up.)
a b floordiv
------------------
(a/b)
-combinator
Run two quoted programs in parallel and replace them with their results.
+All the division commands need to be revisited when the "numeric tower" +for Thun gets nailed down.
combinator
Run two quoted programs in parallel and replace them with their results.
... [F] [G] fork
----------------------
... f g
-Replace a list with its fourth item.
+The basic parallelism combinator, the two programs are run independently.
Replace a list with its fourth item.
[a b c d ...] fourth
--------------------------
d
-Take two integers from the stack and replace them with their Greatest -Common Denominator.
Greater-than-or-equal-to comparison of two numbers.
+Take two integers from the stack and replace them with their Greatest +Common Denominator.
Euclid's Algorithm
built-in
Greater-than-or-equal-to comparison of two numbers.
a b ge
--------------
Boolean
(a >= b)
-combinator
General Recursion Combinator.
[if] [then] [rec1] [rec2] genrec
---------------------------------------------------------------------
[if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte
-Note that this definition includes the genrec symbol itself, it is
self-referential. This is possible because the definition machinery does
-not check that symbols in defs are in the dictionary. `genrec` is the
+not check that symbols in defs are in the dictionary. genrec is the
only self-referential definition.
-See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
-From ["Recursion Theory and Joy"](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html)
-by Manfred von Thun:
-> "The genrec combinator takes four program parameters in addition to
-> whatever data parameters it needs. Fourth from the top is an if-part,
-> followed by a then-part. If the if-part yields true, then the then-part
-> is executed and the combinator terminates. The other two parameters are
-> the rec1-part and the rec2-part. If the if-part yields false, the
-> rec1-part is executed. Following that the four program parameters and
-> the combinator are again pushed onto the stack bundled up in a quoted
-> form. Then the rec2-part is executed, where it will find the bundled
-> form. Typically it will then execute the bundled form, either with i
-> or with app2, or some other combinator."
-The way to design one of these is to fix your base case `[then]` and the
-test `[if]`, and then treat `rec1` and `rec2` as an else-part
+See the Recursion Combinators notebook.
+From "Recursion Theory and Joy"
+by Manfred von Thun:
+"The genrec combinator takes four program parameters in addition to +whatever data parameters it needs. Fourth from the top is an if-part, +followed by a then-part. If the if-part yields true, then the then-part +is executed and the combinator terminates. The other two parameters are +the rec1-part and the rec2-part. If the if-part yields false, the +rec1-part is executed. Following that the four program parameters and +the combinator are again pushed onto the stack bundled up in a quoted +form. Then the rec2-part is executed, where it will find the bundled +form. Typically it will then execute the bundled form, either with i +or with app2, or some other combinator." +The way to design one of these is to fix your base case
[then]and the +test[if], and then treatrec1andrec2as an else-part "sandwiching" a quotation of the whole function. -For example, given a (general recursive) function `F`: +For example, given a (general recursive) functionF: F == [I] [T] [R1] [R2] genrec -If the `[I]` if-part fails you must derive `R1` and `R2` from: : +If the[I]if-part fails you must deriveR1andR2from: : ... R1 [F] R2 -Just set the stack arguments in front, and figure out what `R1` and `R2` -have to do to apply the quoted `[F]` in the proper way. In effect, the -`genrec` combinator turns into an [ifte] combinator with a quoted copy of +Just set the stack arguments in front, and figure out whatR1andR2+have to do to apply the quoted[F]in the proper way. In effect, the +genreccombinator turns into an [ifte] combinator with a quoted copy of the original definition in the else-part: F == [I] [T] [R1] [R2] genrec == [I] [T] [R1 [F] R2] ifte -Tail recursive functions are those where `R2` is the `i` combinator: +Tail recursive functions are those whereR2is theicombinator: 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 + == [I] [T] [R P] ifte
+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
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
-----------------------
a b [c d e]
-A weird function used in [app2] that does this:
... 1 2 3 4 5 grba
-------------------------------
... 1 2 3 [4 3 2 1 ...] 5
-It grabs the stack under the top item, and substitutes it for the second item down on the stack.
Greater-than comparison of two numbers.
+It grabs the stack under the top item, and substitutes it for the second item down on the stack.
This function "grabs" an item from the stack along with a copy of the stack. +It's part of the [app2] definition.
Accepts a quoted symbol on the top of the stack and prints its +
Accepts a quoted symbol on the top of the stack and prints its documentation.
[foo] help
----------------
- x y hypot
+Technically this is equivalent to pop, but it will only work if the
+item on the top of the stack is a quoted symbol.
x y hypot
---------------------------
sqrt(sqr(x) + sqr(y))
-combinator built-in
Append a quoted expression onto the pending expression.
+This is another function that has to wait on the numeric tower.
combinator built-in
Append a quoted expression onto the pending expression.
[Q] . i
-------------
. Q
-The identity function.
combinator
If-Then-Else combinator, a common and convenient specialization of [branch].
+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].
[if] [then] [else] ifte
---------------------------------------
[if] nullary [else] [then] branch
-combinator
Take a quoted program from the stack and run it twice, first under the top item, then again with the top item.
... a [Q] ii
------------------
@@ -420,13 +427,13 @@ top item, then again with the top item.
1 2 4 4 [++] • i
1 2 4 4 • ++
1 2 4 5 •
-In some cases (like the example above) this is the same effect as using [app2] but most of the time it's not: 1 2 3 4 [+] ii -------------------- 1 9 1 2 3 4 [+] app2 ---------------------- - 1 2 5 6
combinator
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
---------------------------------
@@ -441,23 +448,23 @@ c b a [F] i [...] swaack
c b a F [...] swaack
d e [...] swaack
... [e d]
-This is one of the more useful combinators. It allows a quoted expression to serve as a stack for a program, effectively running it in a kind of "pocket universe". If the list represents a datastructure then -`infra` lets you work on its internal structure.
Create a new Joy function definition in the Joy dictionary. A definition
+infra lets you work on its internal structure.
built-in
Create a new Joy function definition in the Joy dictionary. A definition is given as a quote with a name followed by a Joy expression.
[sqr dup mul] inscribe
-This is the only function that modifies the dictionary. It's provided as a convenience, for tinkering with new definitions before entering them into -the `defs.txt` file. It can be abused, which you should avoid unless you -know what you're doing.
Less-Than-or-Equal-to comparison of the two items on the top of the
+the defs.txt file. It can be abused, which you should avoid unless you
+know what you're doing.
built-in
Less-Than-or-Equal-to comparison of the two items on the top of the stack, replacing them with a Boolean value.
a b le
-------------
Boolean
(a <= b)
-combinator built-in
Expect a quoted program Q and a Boolean value on the stack. If the value is false
+
combinator built-in
Expect a quoted program Q and a Boolean value on the stack. If the value is false
discard the quoted program, otherwise run a copy of Q and loop again.
false [Q] loop
--------------------
@@ -466,25 +473,27 @@ discard the quoted program, otherwise run a copy of Q and loo
true [Q] . loop
--------------------------
. Q [Q] loop
-This, along with [branch] and [fork], is one of the four main combinators
of all programming. The fourth, sequence, is implied by juxtaposition.
-That is to say, in Joy `F G` is like `G(F(...))` in a language bassed on
-function application. Or again, to quote the [Joy Wikipedia
-entry](https://en.wikipedia.org/wiki/Joy_(programming_language)#Mathematical_purity),
-> In Joy, the meaning function is a homomorphism from the syntactic monoid onto the semantic monoid. That is, the syntactic relation of concatenation of symbols maps directly onto the semantic relation of composition of functions.
+That is to say, in Joy F G is like G(F(...)) in a language bassed on
+function application. Or again, to quote the Joy Wikipedia
+entry,
+In Joy, the meaning function is a homomorphism from the syntactic monoid onto the semantic monoid. That is, the syntactic relation of concatenation of symbols maps directly onto the semantic relation of composition of functions. Anyway, [branch], [fork], amd [loop] are the fundamental combinators in Joy. Just as [branch] has it's more common and convenient form [ifte], -[loop] has [while].
built-in
Less-Than comparison of the two items on the top of the stack, replacing them with a Boolean value.
a b lt
-------------
Boolean
(a < b)
-Given an initial state value and a quoted generator function build a +
Given an initial state value and a quoted generator function build a generator quote.
state [generator function] make_generator
-----------------------------------------------
@@ -499,15 +508,15 @@ generator quote.
[230 [dup ++] codireco] 5 [x] times pop
---------------------------------------------
230 231 232 233 234
-
combinator
Given a list of items and a quoted program run the program for each item +
combinator
Given a list of items and a quoted program run the program for each item in the list (with the rest of the stack) and replace the old list and the program with a list of the results.
5 [1 2 3] [++ *] map
--------------------------
5 [10 15 20]
-Given a list find the maximum.
+This is a common operation in many languages. In Joy it can be a +parallelism combinator due to the "pure" nature of the language.
Given a list find the maximum.
[1 2 3 4] max
-------------------
@@ -521,7 +530,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)
@@ -535,7 +544,7 @@ stack, replacing them with a Boolean value.
a neg
-----------
-a
-
Like [bool] but convert the item on the top of the stack to the inverse Boolean value.
true not
--------------
@@ -544,11 +553,11 @@ Boolean value.
false not
---------------
true
-Take the item on the top of the stack and [cons] it onto [nullary].
Take the item on the top of the stack and [cons] it onto [nullary].
[F] nulco
-------------------
[[F] nullary]
-combinator
Run a quoted program without using any stack values and leave the first +
Helper function for [or] and [and].
combinator
Run a quoted program without using any stack values and leave the first item of the result on the stack.
... [P] nullary
---------------------
@@ -561,14 +570,14 @@ item of the result on the stack.
... [...] [P] infra first
... [a ...] first
... a
-A very useful function that runs any other quoted function and returns it's first result without disturbing the stack (under the quoted -program.)
Like [getitem] but [swap]s the order of arguments.
+program.)Like [getitem] but [swap]s the order of arguments.
2 [a b c d] of
--------------------
c
-[dup] the second item on the stack over the first.
a b over
--------------
a b a
@@ -582,43 +591,43 @@ program.)combinator
Take a list of quoted functions from the stack and replace it with a list +
And so on...
A fine old word from Forth.
combinator
Take a list of quoted functions from the stack and replace it with a list of the [first] results from running those functions (on copies of the rest of the stack.)
5 7 [[+][-][*][/][%]] pam
-------------------------------
5 7 [12 -2 35 0 5]
-Plus or minus. Replace two numbers with their sum and difference.
+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.
a b pm
-----------------
(a+b) (a-b)
-[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
-[pop] two items from the stack.
+[pop] two items from the stack.
a b popop
---------------
-[pop] the second and third items from the stack.
+[pop] the second and third items from the stack.
a b c popopd
------------------
c
- a b c d popopdd
---------------------
c d
-[pop] three items from the stack.
+[pop] three items from the stack.
a b c popopop
-------------------
-Take two numbers a and n from the stack and raise a to the nth
+
Take two numbers a and n from the stack and raise a to the nth
power. (n is on the top of the stack.)
a n pow
-------------
@@ -628,7 +637,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 @@ -652,8 +661,8 @@ element on the stack.
n [Base] [Recur] primrec ------------------------------------------ n > 0 n (n-1) [Base] [Recur] primrec Recur -
Just as [sum] sums a list of numbers, this function multiplies them +
Simple and useful specialization of the [genrec] combinator from the +original Joy system.
Just as [sum] sums a list of numbers, this function multiplies them together.
@@ -662,11 +671,11 @@ together.Or,
[1] [[mul]] [primrec]
-
"Quote D" Wrap the second item on the stack in a list.
a b quoted
----------------
[a] b
-Expect a number n on the stack and replace it with a list:
+
This comes from the original Joy stuff.
Expect a number n on the stack and replace it with a list:
[(n-1)...0].
5 range
@@ -676,17 +685,17 @@ together.
-5 range
--------------
[]
-[0 <=] [-- dup] anamorphism
Take a number n from the stack and replace it with a list
+
If n is less than 1 the resulting list is empty.
Take a number n from the stack and replace it with a list
[0...n].
5 range_to_zero
---------------------
[0 1 2 3 4 5]
-unit [down_to_zero] infra
Replace the first item in a list with the item under it.
+Note that the order is reversed compared to [range].
Replace the first item in a list with the item under it.
a [b ...] reco
--------------------
[a ...]
-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
@@ -697,34 +706,34 @@ 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
---------------------
[3 2 1]
-Round a number to a given precision in decimal digits.
Round a number to a given precision in decimal digits.
Another one that won't make sense until the "numeric tower" is nailed +down.
Use a Boolean value to select one of two items from a sequence. :
[a b] false select
------------------------
a
@@ -732,60 +741,60 @@ down.Print redistribution information.
Move the top item from one list to another.
+The sequence can contain more than two items but not fewer.
Print redistribution information.
Mathematically this is a form of [id], but it has the side-effect of +printing out the GPL notice.
Move the top item from one list to another.
[x y z] [a b c] shift
---------------------------
[a x y z] [b c]
-Like [concat] but [reverse] the top list into the second.
[a b c] [d e f] shunt
---------------------------
[f e d a b c]
-Replace a list with its size.
+This is more efficient than [concat] so prefer it if you don't need to +preserve order.
Replace a list with its size.
[23 [cats] 4] size
------------------------
3
-Given a list return it sorted.
[4 2 5 7 1] sort
----------------------
[1 2 4 5 7]
-Example code.
[[[abs] ii <=] [[<>] [pop !-] or] and] [[!-] [[++]] [[--]] ifte dip] [[pop !-] [--] [++] ifte] ifte
Split a list (second on the stack) at the position given by the number on +
Split a list (second on the stack) at the position given by the number on the top of the stack.
[1 2 3 4 5 6 7] 4 split_at
--------------------------------
[5 6 7] [4 3 2 1]
-Split a list (second on the stack) at the position given by the number on +
Take a list and a number n from the stack, take n items from the top
+of the list and [shunt] them onto a new list that replaces the number n
+on the top of the stack.
Split a list (second on the stack) at the position given by the number on the top of the stack such that [concat] would reconstruct the original list.
[1 2 3 4 5 6 7] 4 split_list
----------------------------------
[1 2 3 4] [5 6 7]
-Square the number on the top of the stack.
+Compare with [split_at]. This function does extra work to ensure that +[concat] would reconstruct the original list.
Function Combinator
Return the square root of the number a. Negative numbers return complex -roots.
built-in
Put the stack onto the stack.
+roots.Another "numeric tower" hatch...
built-in
Put the stack onto the stack.
... c b a stack
---------------------------
... c b a [a b c ...]
-Grab the stack under the top item and put it onto the stack.
+This function forms a pair with [unstack], and together they form the +complement to the "destructive" pair [enstacken] and [disenstacken].
Grab the stack under the top item and put it onto the stack.
... 1 2 3 stackd
------------------------
... 1 2 [2 1 ...] 3
-combinator
Run a quoted program on each item in a sequence.
... [] [Q] step
---------------------
...
@@ -799,22 +808,22 @@ complement to the "destructive" pair [enstacken] and [disenstacken].combinator
Like [step] but with 0 as the initial value.
+See the Recursion Combinators notebook.
combinator
Like [step] but with 0 as the initial value.
[...] [F] step_zero
-------------------------
0 [...] [F] step
-Take the [stack] and [uncons] the top item.
+[size] and [sum] can both be defined in terms of this specialization of +[step].
Take the [stack] and [uncons] the top item.
1 2 3 stuncons
--------------------
1 2 3 3 [2 1]
-Take the [stack] and [uncons] the top two items.
1 2 3 stununcons
----------------------
1 2 3 3 2 [1]
-built-in
Subtract the number on the top of the stack from the number below it.
a b sub
-------------
(a-b)
@@ -823,14 +832,14 @@ complement to the "destructive" pair [enstacken] and [disenstacken]. [1 2 3 4 5] sum
---------------------
15
-built-in
Swap stack. Take a list from the top of the stack, replace the stack +
built-in
Swap stack. Take a list from the top of the stack, replace the stack with the list, and put the old stack onto it.
1 2 3 [4 5 6] swaack
--------------------------
6 5 4 [3 2 1]
-built-in
Swap the top two items on the stack.
+This function works as a kind of "context switch". It's used in the +definition of [infra].
built-in
Swap the top two items on the stack.
a b swap
--------------
b a
@@ -838,29 +847,29 @@ definition of [infra].Like [cons] but [swap] the item and list.
+Like [cons] but [swap] the item and list.
[...] a swons
-------------------
[a ...]
-combinator
A specialization of the [genrec] combinator.
combinator
A specialization of the [genrec] combinator.
Some recursive functions do not need to store additional data or pending +actions per-call. These are called "tail recursive" functions. In Joy, they appear as [genrec] definitions that have [i] for the second half of their recursive branch. -See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
Expects an integer n and a list on the stack and replace them with a list
+See the Recursion Combinators notebook.
Expects an integer n and a list on the stack and replace them with a list
with just the top n items in reverse order.
[a b c d] 2 take
----------------------
[b a]
-combinator
Run a quoted program using exactly three stack values and leave the first item of the result on the stack.
... z y x [P] ternary
-------------------------
... a
- [a b c ...] third
+Runs any other quoted function and returns its first result while +consuming exactly three items from the stack.
combinator
Expect a quoted program and an integer n on the stack and do the
program n times.
... n [Q] . times
----------------------- w/ n <= 0
@@ -873,7 +882,7 @@ program n times.
... n [Q] . times
------------------------------------- w/ n > 1
... . Q (n-1) [Q] times
-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
--------------
b a b
-(Combinator)
Run a quoted program using exactly one stack value and leave the first item of the result on the stack.
... x [P] unary
---------------------
... a
-Removes an item from a list and leaves it on the stack under the rest of +
Runs any other quoted function and returns its first result while +consuming exactly one item from the stack.
Removes an item from a list and leaves it on the stack under the rest of
the list. You cannot uncons an item from an empty list.
[a ...] uncons
--------------------
a [...]
-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
--------------------------
1 2 3 4 5
-True if the form on TOS is void otherwise False.
True if the form on TOS is void otherwise False.
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/)
Print warranty information.
combinator
A specialization of [loop] that accepts a quoted predicate program P
+"Laws of Form", see The Markable Mark
Print warranty information.
combinator
A specialization of [loop] that accepts a quoted predicate program P
and runs it [nullary].
[P] [F] while
------------------- P -> false
@@ -925,27 +934,27 @@ and runs it [nullary].
[P] [F] while
--------------------- P -> true
F [P] [F] while
-Print all the words in alphabetical order.
combinator
Take a quoted function F and run it with itself as the first item on
+
Print all the words in alphabetical order.
Mathematically this is a form of [id].
combinator
Take a quoted function F and run it with itself as the first item on
the stack.
[F] x
-----------
[F] F
-The simplest recursive pattern. +See the Recursion Combinators notebook. as well as -[Recursion Theory and Joy](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html) by Manfred von
Replace the two lists on the top of the stack with a list of the pairs +Recursion Theory and Joy by Manfred von
Replace the two lists on the top of the stack with a list of the pairs 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]]
-combinator
Short-circuiting Boolean OR
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.)
[A] [B] ||
---------------- A -> false
B
[A] [B] ||
---------------- A -> true
- true