-Function
-
Not negative.
@@ -15,32 +13,23 @@ Not negative.
---------- n >= 0
true
-
-### Definition
-
- 0 \>=
-
-### Discussion
-
-Return a Boolean value indicating if a number is greater than or equal to
-zero.
-
-
@@ -70,186 +59,122 @@ stack.)
TODO: this is derived in one of the notebooks I think, look it up and
link to it, or copy the content here.
-
-### Discussion
-
-This is seldom useful, I suspect, but this way you have it.
-
-### Crosslinks
-
-[||](#section-25)
-
-
-Function
-
... b a <{}
-----------------
... [] b a
-
-### Definition
-
- [] rollup
-
-
-### Discussion
-
-Tuck an empty list just under the first two items on the stack.
-
-### Crosslinks
-
-[<{}](#section-16)
-
-
-Function
-
... a <{}
----------------
... [] a
-
-### Definition
-
- [] swap
-
-### Discussion
-
-Tuck an empty list just under the first item on the stack.
-
-### Crosslinks
-
-[<<{}](#section-18)
-
-
-Function
-
Is the item on the top of the stack "truthy"?
-
-### Definition
-
-> [dup](#dup) [bool](#bool)
-
-### Discussion
-
-You often want to test the truth value of an item on the stack without
-consuming the item.
-
-### Crosslinks
-
-[bool](#bool)
-
-
@@ -260,33 +185,16 @@ predicate `P`.
-----------------------------------------
[P] [pop []] [G] [dip swons] genrec
-### Definition
-
-> \[[pop](#pop) \[\]\] [swap](#swap) \[[dip](#dip) [swons](#swons)\] [genrec](#genrec)
-
### Example
The `range` function generates a list of the integers from 0 to n - 1:
> \[0 <=\] \[\-\- dup\] anamorphism
+
"apply one"
@@ -301,24 +209,8 @@ the first result of the program.
... [x ...] [Q] infra first
This is the same effect as the [unary](#unary) combinator.
-
-### Definition
-
-> [nullary](#nullary) [popd](#popd)
-
-### Discussion
-
-Just a specialization of `nullary` really. Its parallelizable cousins
-are more useful.
-
-### Crosslinks
-
-[app2](#app2)
-[app3](#app3)
-[appN](#appN)
-[unary](#unary)
-
-
@@ -329,30 +221,14 @@ Like [app1](#app1) with two items.
... [y ...] [Q] . infra first
[x ...] [Q] infra first
-### Definition
-
-> \[[grba] [swap] [grba] [swap]\] [dip] \[[infrst]\] [cons] [ii]
-
-### Discussion
-
-Unlike [app1](#app1), which is essentially an alias for [unary](#unary),
+
Unlike [app1](#app1), which is essentially an alias for [unary](#unary),
this function is not the same as [binary](#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
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.
-
-### Crosslinks
-
-[app1](#app1)
-[app3](#app3)
-[appN](#appN)
-[unary](#unary)
-
-
@@ -392,52 +252,24 @@ Like [app1] with any number of items.
[x2 ...] [Q] infra first
[x1 ...] [Q] infra first
[x0 ...] [Q] infra first
-
-### Definition
-
-> \[[grabN]\] [codi] [map] [disenstacken]
-
-### Discussion
-
-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].
-
-### Crosslinks
-
-[app1](#app1)
-[app2](#app2)
-[app3](#app3)
-[unary](#unary)
-
-
-Function
-
Compute the average of a list of numbers.
(Currently broken until I can figure out what to do about "numeric tower"
in Thun.)
-
-### Definition
-
-> \[[sum]\] \[[size]\] [cleave] [/]
-
-### Discussion
-
-Theoretically this function would compute the sum and the size in two
+
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).
-
-
@@ -446,21 +278,7 @@ Run two quoted programs
[P] [Q] b
---------------
P Q
-
-### Definition
-
-> \[[i]\] [dip] [i]
-
-### Discussion
-
-This combinator may seem trivial but it comes in handy.
-
-### Crosslinks
-
-[dupdip](#dupdip)
-[ii](#ii)
-
-
-### Definition
-
-> [unary] [popd]
-
-### Discussion
-
-Runs any other quoted function and returns its first result while
-consuming exactly two items from the stack.
-
-### Crosslinks
-
-[nullary](#nullary)
-[ternary](#ternary)
-[unary](#unary)
-
-
-
-
-Function
Convert the item on the top of the stack to a Boolean value.
-
-### Discussion
-
-For integers 0 is `false` and any other number is `true`; for lists the
-empty list is `false` and all other lists are `true`.
-
-### Crosslinks
-
-[not]
-
-
@@ -517,66 +309,26 @@ Use a Boolean value to select and run one of two quoted programs.
-------------------------
T
-
-### Definition
-
-> [rolldown] [choice] [i]
-
-### Discussion
-
-This is one of the fundamental operations (although it can be defined in
+
Discussion
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].
+[ifte] adds a predicate function that is evaluated [nullary].
-
-
-Function
Use a Boolean value to select one of two items.
@@ -587,38 +339,12 @@ Use a Boolean value to select one of two items.
a b true choice
---------------------
b
+
Discussion
It's a matter of taste whether you implement this in terms of [branch] or
+the other way around.
-### Definition
-
-> \[[pop]\] \[[popd]\] [branch]
-
-### Discussion
-
-It's a matter of taste whether you implement this in terms of [branch] or
-the other way around.
-
-### Crosslinks
-
-[branch]
-[select]
-
-
@@ -658,26 +373,10 @@ Run two programs in parallel, consuming two additional items, and put their resu
... x y [A] [B] clop
--------------------------
... a b
-
-### Definition
-
-> [cleave] [popdd]
-
-### Discussion
-
-Like [cleave] but consumes an additional item from the stack.
-
+
@@ -694,26 +393,13 @@ of the three depending on the results of comparing the two values.
a b [G] [E] [L] cmp
------------------------- a < b
- L
-### Discussion
-
-This is useful sometimes, and you can [dup] or [dupd] with two quoted
+ 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
-
-### Crosslinks
-
-TODO: link to tree notebooks where this was used.
-
-
@@ -723,77 +409,25 @@ Take a quoted program from the stack, [cons] the next item onto it, then
a b [F] . codi
--------------------
b . F a
-
-### Definition
-
-> [cons] [dip]
-
-### Discussion
-
-This is one of those weirdly specific functions that turns out to be
-useful in a few places.
-
-### Crosslinks
-
-[appN]
-[codireco]
-
-
This is part of the [make_generator] function. You would not use this
combinator directly.
-
-### Definition
-
-> [codi] [reco]
-
-### Discussion
-
-See [make_generator] and the
+
See [make_generator] and the
["Using `x` to Generate Values" notebook](https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation)
as well as
-[Recursion Theory and Joy](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html) by Manfred von Thun.
+[Recursion Theory and Joy](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html) by Manfred von Thun.
@@ -811,52 +445,25 @@ followed by the function expression to run if that predicate returns
[Default]
]
cond
-
-### Discussion
-
-It works by rewriting into a chain of nested [ifte]{.title-ref}
+
Discussion
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
+ [B0] [T0] [[B1] [T1] [D] ifte] ifte
-
-
-Function
-
Given an item and a list, append the item to the list to make a new list.
a [...] cons
------------------
[a ...]
-
-### Discussion
-
-Cons is a [venerable old function from Lisp](https://en.wikipedia.org/wiki/Cons#Lists).
-Its inverse operation is [uncons].
-
-### Crosslinks
-
-[uncons]
-
-
@@ -867,12 +474,8 @@ on the rest of the stack.
... x [Q] . dip
---------------------
... . Q x
-
-### Discussion
-
-This along with [infra] are enough to update any datastructure.
+
Discussion
This along with [infra] are enough to update any datastructure.
See the ["Traversing Datastructures with Zippers" notebook](https://joypy.osdn.io/notebooks/Zipper.html).
-
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
@@ -883,17 +486,7 @@ 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.)
-
-### Crosslinks
-
-[dipd]
-[dipdd]
-[dupdip]
-[dupdipd]
-[infra]
-
-
@@ -922,23 +503,8 @@ Like [dip] but expects three items. :
... z y x [Q] . dip
-----------------------------
- ... . Q z y x
-### Discussion
+ ... . Q z y x
-
-
-Function
The `disenstacken` function expects a list on top of the stack and makes
that the stack discarding the rest of the stack.
@@ -946,33 +512,16 @@ that the stack discarding the rest of the stack.
1 2 3 [4 5 6] disenstacken
--------------------------------
6 5 4
-
-### Definition
-
-> \[[clear]\] [dip] [reverse] [unstack](#unstack)
-
-### Discussion
-
-Note that the order of the list is not changed, it just looks that way
+
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.
-
-### Crosslinks
-
-[enstacken]
-[stack]
-[unstack](#unstack)
-
-
-
-
-Function
Given a number greater than zero put all the Natural numbers (including
zero) less than that onto the stack.
@@ -998,19 +540,8 @@ zero) less than that onto the stack.
3 down_to_zero
--------------------
3 2 1 0
+
-
-
-Function
Expects an integer and a quote on the stack and returns the quote with n
items removed off the top.
@@ -1020,78 +551,31 @@ items removed off the top.
[a b c d] 2 drop
----------------------
[c d]
+
-
-
-Function
[dup] the third item down on the stack.
a b c dupdd
-----------------
a a b c
-
-### Definition
-
-> \[[dup]\] [dipd]
-
-### Crosslinks
-
-[dup]
-[dupd]
-[dupdip]
-[dupdipd]
-
-
@@ -1101,10 +585,6 @@ Apply a function `F` and [dup] the item under it on the stack.
------------------
a F a
-### Definition
-
-> [dupd] [dip]
-
### Derivation
a [F] dupdip
@@ -1113,16 +593,7 @@ Apply a function `F` and [dup] the item under it on the stack.
a dup [F] dip
a a [F] dip
a F a
-
-### Discussion
-
-A very common and useful combinator.
-
-### Crosslinks
-
-[dupdipd]
-
-
-
-
-Function
Put the stack onto the stack replacing the contents of the stack.
@@ -1151,26 +611,9 @@ Put the stack onto the stack replacing the contents of the stack.
-------------------------
[c b a ...]
+
-### Definition
-
-> [stack] \[[clear]\] [dip]
-
-### Discussion
-
-This is a destructive version of [stack]. See the note under
-[disenstacken] about the apparent but illusory reversal of the stack.
-
-### Crosslinks
-
-[stack]
-[unstack]
-[disenstacken]
-
-
-
-
-Function
Compare the two items on the top of the stack for equality and replace
them with a Boolean value.
@@ -1179,65 +622,24 @@ them with a Boolean value.
-------------
Boolean
(a = b)
+
-
-
-Function
Given a list of lists, concatinate them.
@@ -1246,54 +648,14 @@ Given a list of lists, concatinate them.
[[1 2] [3 [4] 5] [6 7]] flatten
-------------------------------------
[1 2 3 [4] 5 6 7]
+
-
-
-Function
I don't know why this is called "floor" div, I think it rounds its
result down (not towards zero or up.)
@@ -1301,17 +663,8 @@ result down (not towards zero or up.)
a b floordiv
------------------
(a/b)
-
-### Discussion
-
-All the division commands need to be revisited when the "numeric tower"
-for Thun gets nailed down.
-
-### Crosslinks
-
-[divmod]
-
-
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
-only self-referential definition.)
-
-### Discussion
-
+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
@@ -1445,43 +725,24 @@ by Manfred von Thun:
> 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
"sandwiching" a quotation of the whole function.
-
For example, given a (general recursive) function `F`:
-
F == [I] [T] [R1] [R2] genrec
-
If the `[I]` if-part fails you must derive `R1` and `R2` from: :
-
... 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
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:
-
P == [I] [T] [R] tailrec
== [I] [T] [R [P] i] ifte
- == [I] [T] [R P] ifte
+ == [I] [T] [R P] ifte
-
-
-Function
Expects an integer and a quote on the stack and returns the item at the
nth position in the quote counting from 0.
@@ -1491,42 +752,10 @@ nth position in the quote counting from 0.
[a b c d] 2 getitem
-------------------------
c
-
-### Definition
-
-> [drop] [first]
-
-### Discussion
-
-If the number isn't a valid index into the quote `getitem` will cause
+
Discussion
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.)
+implementation-dependant.)
-
-
-Function
Expect a number on the top of the stack and [cons] that many items from under it onto a new list.
@@ -1535,14 +764,8 @@ Expect a number on the top of the stack and [cons] that many items from under it
a b c d e 3 grabN
-----------------------
a b [c d e]
+
-
-
-Function
A weird function used in [app2] that does this:
@@ -1551,23 +774,9 @@ A weird function used in [app2] that does this:
... 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.
+
-### Definition
-
-> \[[stack] [popd]\] [dip]
-
-### Discussion
-
-This function "grabs" an item from the stack along with a copy of the stack.
-It's part of the [app2] definition.
-
-### Crosslinks
-
-[app2]
-
-
-
-Function
x y hypot
---------------------------
sqrt(sqr(x) + sqr(y))
-
-### Definition
-
-> \[[sqr]\] [ii] [+] [sqrt]
-
-### Discussion
-
-This is another function that has to wait on the numeric tower.
-
-### Crosslinks
-
-[sqrt]
-
-
-### Discussion
-
-This is a fundamental combinator. It is used in all kinds of places. For
-example, the [x] combinator can be defined as `dup i`.
-
-
@@ -1677,10 +834,6 @@ top item, then again with the top item.
------------------
... Q a Q
-### Definition
-
-> \[[dip]\] [dupdip] [i]
-
### Example
It's a little tricky to understand how this works so here's an example trace:
@@ -1694,24 +847,13 @@ It's a little tricky to understand how this works so here's an example trace:
1 2 4 4 [++] • i
1 2 4 4 • ++
1 2 4 5 •
-
-### Discussion
-
-In some cases (like the example above) this is the same effect as using [app2] but most of the time it's not:
-
+
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
-
-### Crosslinks
-
-[app2]
-[b]
-
@@ -1722,10 +864,6 @@ the list as its stack. Does not affect the stack (below the list.)
---------------------------------
c b a Q [z y x ...] swaack
-### Definition
-
-> [swons] [swaack] \[[i]\] [dip] [swaack]
-
... [a b c] [F] swons swaack [i] dip swaack
... [[F] a b c] swaack [i] dip swaack
@@ -1736,29 +874,15 @@ the list as its stack. Does not affect the stack (below the list.)
d e [...] swaack
... [e d]
-
-### Discussion
-
-This is one of the more useful combinators. It allows a quoted
+
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.
-
-### Crosslinks
-
-[swaack](#swaack)
-
-
Create a new Joy function definition in the Joy dictionary. A definition
@@ -1767,18 +891,12 @@ is given as a quote with a name followed by a Joy expression.
### Example
[sqr dup mul] inscribe
-
-### Discussion
-
-This is the only function that modifies the dictionary. It's provided as a
+
Discussion
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.
-
-Function
-
Less-Than-or-Equal-to comparison of the two items on the top of the
stack, replacing them with a Boolean value.
@@ -1786,16 +904,7 @@ stack, replacing them with a Boolean value.
-------------
Boolean
(a <= b)
-
-### Crosslinks
-
-[cmp]
-[eq]
-[ge]
-[gt]
-[lt]
-[ne]
-
@@ -1809,44 +918,24 @@ discard the quoted program, otherwise run a copy of `Q` and `loop` again.
true [Q] . loop
--------------------------
. Q [Q] loop
-
-### Discussion
-
-This, along with [branch] and [fork], is one of the four main combinators
+
Discussion
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.
-
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].
+[loop] has [while].
-
-
-Function
Less-Than comparison of the two items on the top of the
stack, replacing them with a Boolean value.
@@ -1855,19 +944,8 @@ stack, replacing them with a Boolean value.
-------------
Boolean
(a < b)
+
-
-
-Function
Given an initial state value and a quoted generator function build a
generator quote.
@@ -1887,20 +965,7 @@ And then:
[230 [dup ++] codireco] 5 [x] times pop
---------------------------------------------
230 231 232 233 234
-
-### Definition
-
-> \[[codireco]\] [ccons]
-
-### Discussion
-
-See the ["Using `x` to Generate Values" notebook](https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation).
-
-### Crosslinks
-
-[codireco]
-
-
-### Discussion
-
-This is a common operation in many languages. In Joy it can be a
-parallelism combinator due to the "pure" nature of the language.
-
-### Crosslinks
-
-[app1]
-[app2]
-[app3]
-[appN](#appn)
-[fork]
-
-
-
-
-Function
Not-Equal comparison of the two items on the top of the
stack, replacing them with a Boolean value.
@@ -2014,33 +1030,16 @@ stack, replacing them with a Boolean value.
-------------
Boolean
(a = b)
+
-
-
-Function
Like [bool] but convert the item on the top of the stack to the inverse
Boolean value.
@@ -2052,40 +1051,15 @@ Boolean value.
false not
---------------
true
-
-### Definition
+
-
-
-Function
Take the item on the top of the stack and [cons] it onto `[nullary]`.
[F] nulco
-------------------
[[F] nullary]
-
-### Definition
-
-> \[[nullary]\] [cons]
-
-### Discussion
-
-Helper function for [\|\|] and [&&].
-
-### Crosslinks
-
-[&&]
-[\|\|]
-
-
@@ -2096,10 +1070,6 @@ item of the result on the stack.
---------------------
... a
-### Definition
-
-> \[[stack]\] [dip] [infra] [first]
-
### Example
... [P] nullary
@@ -2108,23 +1078,10 @@ item of the result on the stack.
... [...] [P] infra first
... [a ...] first
... a
-
-### Discussion
-
-A very useful function that runs any other quoted function and returns
+
A very useful function that runs any other quoted function and returns
it's first result without disturbing the stack (under the quoted
-program.)
+program.)
-
-
-Function
Like [getitem] but [swap]s the order of arguments.
@@ -2133,31 +1090,12 @@ Like [getitem] but [swap]s the order of arguments.
2 [a b c d] of
--------------------
c
+
-
-
-Function
[dup] the second item on the stack `over` the first.
@@ -2180,16 +1118,7 @@ There are many many ways to define this function.
> [unit] [dupdipd] [first]
And so on...
-
-### Discussion
-
-A fine old word from Forth.
-
-### Crosslinks
-
-[tuck]
-
-
@@ -2202,203 +1131,73 @@ rest of the stack.)
5 7 [[+][-][*][/][%]] pam
-------------------------------
5 7 [12 -2 35 0 5]
-
-### Definition
-
-> \[[i]\] [map]
-
-### Discussion
-
-A specialization of [map] that runs a list of functions in parallel (if
-the underlying [map] function is so implemented, of course.)
-
-### Crosslinks
-
-[map]
-
-
-
-
-Function
Take two numbers `a` and `n` from the stack and raise `a` to the `n`th
power. (`n` is on the top of the stack.)
@@ -2413,22 +1212,11 @@ power. (`n` is on the top of the stack.)
-----------------------------------
2 [4 8 16 32 64 128 256 512]
-
@@ -2459,21 +1247,9 @@ From the ["Overview of the language JOY"](https://www.kevinalbrecht.com/code/joy
n [Base] [Recur] primrec
------------------------------------------ n > 0
n (n-1) [Base] [Recur] primrec Recur
+
Discussion
Simple and useful specialization of the [genrec] combinator from the
+[original Joy system](https://www.kevinalbrecht.com/code/joy-mirror/index.html).
-### Discussion
-
-Simple and useful specialization of the [genrec] combinator from the
-[original Joy system](https://www.kevinalbrecht.com/code/joy-mirror/index.html).
-
-### Crosslinks
-
-[genrec]
-[tailrec]
-
-
-
-
-Function
Expect a number `n` on the stack and replace it with a list:
`[(n-1)...0]`.
@@ -2527,23 +1286,8 @@ Expect a number `n` on the stack and replace it with a list:
-5 range
--------------
[]
+
-
-
-Function
Take a number `n` from the stack and replace it with a list
`[0...n]`.
@@ -2553,55 +1297,27 @@ Take a number `n` from the stack and replace it with a list
5 range_to_zero
---------------------
[0 1 2 3 4 5]
+
-
-
-Function
Replace the first item in a list with the item under it.
a [b ...] reco
--------------------
[a ...]
-
-### Definition
-
-> [rest] [cons]
-
-### Crosslinks
-
-[codireco]
-[make_generator]
-
-
-Function
-
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.
@@ -2614,24 +1330,14 @@ or the item isn't in the list then the list is unchanged.
See the ["Remove Function" notebook](https://osdn.net/projects/joypy/scm/git/Thun/blobs/master/docs/notebooks/Remove-Function.ipynb).
-
-
-
-Function
Reverse the list on the top of the stack.
@@ -2641,100 +1347,49 @@ Reverse the list on the top of the stack.
---------------------
[3 2 1]
-### Definition
-
-> [\<\{\}] [shunt]
-
-
-
-
-Function
Use a Boolean value to select one of two items from a sequence. :
@@ -2781,35 +1416,13 @@ Use a Boolean value to select one of two items from a sequence. :
[a b] true select
-----------------------
b
+
Discussion
The sequence can contain more than two items but not fewer.
-### Discussion
-
-Mathematically this is a form of [id], but it has the side-effect of
-printing out the GPL notice.
-
-### Crosslinks
-
-[warranty]
-
-
-
-
-Function
Move the top item from one list to another.
@@ -2818,19 +1431,8 @@ Move the top item from one list to another.
[x y z] [a b c] shift
---------------------------
[a x y z] [b c]
+
-
-
-Function
Like [concat] but [reverse] the top list into the second.
@@ -2839,26 +1441,9 @@ Like [concat] but [reverse] the top list into the second.
[a b c] [d e f] shunt
---------------------------
[f e d a b c]
+
-### Definition
-
-> \[[swons]\] [step]
-
-### Discussion
-
-This is more efficient than [concat] so prefer it if you don't need to
-preserve order.
-
-### Crosslinks
-
-[concat]
-[reverse]
-[shift]
-
-
-
-
-Function
Split a list (second on the stack) at the position given by the number on
the top of the stack.
@@ -2909,25 +1479,10 @@ the top of the stack.
[1 2 3 4 5 6 7] 4 split_at
--------------------------------
[5 6 7] [4 3 2 1]
-
-### Definition
-
-> \[[drop]\] \[[take]\] [clop]
-
-### Discussion
-
-Take a list and a number `n` from the stack, take `n` items from the top
+
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.
+on the top of the stack.
-
-
-Function
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
@@ -2936,77 +1491,33 @@ list.
[1 2 3 4 5 6 7] 4 split_list
----------------------------------
[1 2 3 4] [5 6 7]
+
-### Definition
-
-> \[[take] [reverse]\] \[[drop]\] [clop]
-
-### Discussion
-
-Compare with [split_at]. This function does extra work to ensure that
-[concat] would reconstruct the original list.
-
-### Crosslinks
-
-[split_at]
-
-
-### Definition
-
-> \[\] [swaack] [dup] [swaack] [first]
-
-### Discussion
-
-This function forms a pair with [unstack], and together they form the
-complement to the "destructive" pair [enstacken] and [disenstacken].
-
-### Crosslinks
-
-[unstack]
-[enstacken]
-[disenstacken]
-
-
-
-
-Function
Grab the stack under the top item and put it onto the stack.
@@ -3016,11 +1527,7 @@ Grab the stack under the top item and put it onto the stack.
------------------------
... 1 2 [2 1 ...] 3
-### Definition
-
-> \[[stack]\] [dip]
-
-
@@ -3039,16 +1546,7 @@ Run a quoted program on each item in a sequence.
... [a b c] [Q] . step
----------------------------------------
... a . Q [b c] [Q] step
-
-### Discussion
-
-See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
-
-### Crosslinks
-
-[step_zero]
-
-
-### Definition
-
-> 0 [roll>] [step]
-
-### Discussion
-
-[size] and [sum] can both be defined in terms of this specialization of
-[step].
-
-### Crosslinks
-
-[step]
-
-
-
-
-Function
Take the [stack] and [uncons] the top item.
@@ -3083,15 +1566,8 @@ Take the [stack] and [uncons] the top item.
1 2 3 stuncons
--------------------
1 2 3 3 [2 1]
+
-
-
-Function
Take the [stack] and [uncons] the top two items.
@@ -3100,46 +1576,19 @@ Take the [stack] and [uncons] the top two items.
1 2 3 stununcons
----------------------
1 2 3 3 2 [1]
+
-
-
-Function
Swap stack. Take a list from the top of the stack, replace the stack
with the list, and put the old stack onto it.
@@ -3172,70 +1610,29 @@ with the list, and put the old stack onto it.
1 2 3 [4 5 6] swaack
--------------------------
6 5 4 [3 2 1]
+
Discussion
This function works as a kind of "context switch". It's used in the
+definition of [infra].
-
-
-Function
Like [cons] but [swap] the item and list.
@@ -3243,37 +1640,17 @@ Like [cons] but [swap] the item and list.
-------------------
[a ...]
-### Definition
-
-> [swap] [cons]
-
-
A specialization of the [genrec] combinator.
-
-### Definition
-
-> \[[i]\] [genrec]
-
-### Discussion
-
-Some recursive functions do not need to store additional data or pending
+
Some recursive functions do not need to store additional data or pending
actions per-call. These are called ["tail recursive" functions](https://en.wikipedia.org/wiki/Tail_recursive). 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).
-
-
-Function
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.
@@ -3281,12 +1658,7 @@ with just the top `n` items in reverse order.
[a b c d] 2 take
----------------------
[b a]
-
-### Definition
-
-> [\<\<\{\}] \[[shift]\] [times] [pop]
-
-
-### Definition
-
-> [binary] [popd]
-
-### Discussion
-
-Runs any other quoted function and returns its first result while
-consuming exactly three items from the stack.
-
-### Crosslinks
-
-[binary](#binary)
-[nullary](#nullary)
-[unary](#unary)
-
-
@@ -3351,57 +1694,35 @@ program `n` times.
------------------------------------- w/ n > 1
... . Q (n-1) [Q] times
-### Definition
-
-> \[\-- dip\] cons \[swap\] infra \[0 \>\] swap while pop :
-
-
-### Discussion
-
-This works by building a little [while] program and running it:
-
+
This works by building a little [while] program and running it:
1 3 [++] • [-- dip] cons [swap] infra [0 >] swap while pop
1 3 [++] [-- dip] • cons [swap] infra [0 >] swap while pop
1 3 [[++] -- dip] • [swap] infra [0 >] swap while pop
- 1 3 [[++] -- dip] [swap] • infra [0 >] swap while pop
+ 1 3 [[++] -- dip] [swap] • infra [0 >] swap while pop
dip -- [++] • swap [3 1] swaack [0 >] swap while pop
dip [++] -- • [3 1] swaack [0 >] swap while pop
dip [++] -- [3 1] • swaack [0 >] swap while pop
1 3 [-- [++] dip] • [0 >] swap while pop
- 1 3 [-- [++] dip] [0 >] • swap while pop
- 1 3 [0 >] [-- [++] dip] • while pop
-
+ 1 3 [-- [++] dip] [0 >] • swap while pop
+ 1 3 [0 >] [-- [++] dip] • while pop
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.
-
-
-Function
-
[dup] the item on the top of the stack under the second item on the
stack.
a b tuck
--------------
b a b
-
-### Definition
-
-> [dup] \[[swap]\] [dip]
-
-### Crosslinks
-
-[over]
-
-
-### Definition
-
-> [nullary] [popd]
-
-### Discussion
-
-Runs any other quoted function and returns its first result while
-consuming exactly one item from the stack.
-
-### Crosslinks
-
-[binary](#binary)
-[nullary](#nullary)
-[ternary](#ternary)
-
-
-
-
-Function
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.
@@ -3439,36 +1743,18 @@ the list. You cannot `uncons` an item from an empty list.
[a ...] uncons
--------------------
a [...]
+
-
-
-Function
True if the form on TOS is void otherwise False.
-
-### Discussion
-
-A form is any Joy expression composed solely of lists.
+
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/)
+"Laws of Form", see [The Markable Mark](http://www.markability.net/)
The simplest recursive pattern.
See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
as well as
-[Recursion Theory and Joy](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html) by Manfred von
+[Recursion Theory and Joy](https://www.kevinalbrecht.com/code/joy-mirror/j05cmp.html) by Manfred von
-
-
-Function
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.
@@ -3607,39 +1828,19 @@ 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]]
-
Short-circuiting Boolean OR
-
-### Definition
-
-> [nulco](#nulco) \[[nullary](#nullary)\] [dip](#dip) \[true\] [branch](#branch)
-
-### Discussion
-
-Accept two quoted programs, run the first and expect a Boolean value, if
+
Discussion
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
-
-### Crosslinks
-
-[&&](#section-1)
-
diff --git a/docs/html/css/func_ref.css b/docs/html/css/func_ref.css
index d33f775..0a6c7c6 100644
--- a/docs/html/css/func_ref.css
+++ b/docs/html/css/func_ref.css
@@ -2,7 +2,7 @@
body {
background: #fff;
color: black;
- font-family: 'EB Garamond 12';
+ font-family: 'EB Garamond 16';
}
footer {
@@ -21,7 +21,7 @@ pre {
margin-left: 2em;
margin-right: 2em;
margin-bottom: 1em;
- font-family: 'Inconsolata';
+ font-family: monospace, 'Inconsolata';
padding: 0.5em;
}
@@ -50,9 +50,12 @@ a.self_link:hover {
font-family: monospace, 'Inconsolata';
}
-
span.kind {
color: #fff;
background: #555;
padding: 0.1em;
}
+
+h3 {
+ margin-bottom: 0.1em;
+}
diff --git a/docs/reference/Function-Reference.md b/docs/reference/Function-Reference.md
index 97ff124..c285f3a 100644
--- a/docs/reference/Function-Reference.md
+++ b/docs/reference/Function-Reference.md
@@ -10,21 +10,12 @@ Each function, combinator, or definition should be documented here.
## abs
-Function
-
Return the absolute value of the argument.
-### Definition
-
-> [dup](#dup) 0 < [] \[[neg](#neg)\] [branch](#branch)
-
-
------------------------------------------------------------------------
## add
-Function
-
Add two numbers together: a + b.
@@ -90,10 +81,6 @@ predicate `P`.
-----------------------------------------
[P] [pop []] [G] [dip swons] genrec
-### Definition
-
-> \[[pop](#pop) \[\]\] [swap](#swap) \[[dip](#dip) [swons](#swons)\] [genrec](#genrec)
-
### Example
The `range` function generates a list of the integers from 0 to n - 1:
@@ -109,8 +96,6 @@ See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursi
## and
-Function
-
Logical bit-wise AND.
### Crosslinks
@@ -137,10 +122,6 @@ the first result of the program.
This is the same effect as the [unary](#unary) combinator.
-### Definition
-
-> [nullary](#nullary) [popd](#popd)
-
### Discussion
Just a specialization of `nullary` really. Its parallelizable cousins
@@ -167,9 +148,6 @@ Like [app1](#app1) with two items.
... [y ...] [Q] . infra first
[x ...] [Q] infra first
-### Definition
-
-> \[[grba] [swap] [grba] [swap]\] [dip] \[[infrst]\] [cons] [ii]
### Discussion
@@ -205,10 +183,6 @@ Like [app1] with three items.
[y ...] [Q] infra first
[x ...] [Q] infra first
-### Definition
-
-> 3 [appN]
-
### Discussion
See [app2].
@@ -237,10 +211,6 @@ Like [app1] with any number of items.
[x1 ...] [Q] infra first
[x0 ...] [Q] infra first
-### Definition
-
-> \[[grabN]\] [codi] [map] [disenstacken]
-
### Discussion
This function takes a quoted function `Q` and an integer and runs the
@@ -272,16 +242,10 @@ See [getitem](#getitem).
## average
-Function
-
Compute the average of a list of numbers.
(Currently broken until I can figure out what to do about "numeric tower"
in Thun.)
-### Definition
-
-> \[[sum]\] \[[size]\] [cleave] [/]
-
### Discussion
Theoretically this function would compute the sum and the size in two
@@ -306,10 +270,6 @@ item of the result on the stack.
-----------------------
... a
-### Definition
-
-> [unary] [popd]
-
### Discussion
Runs any other quoted function and returns its first result while
@@ -334,10 +294,6 @@ Run two quoted programs
---------------
P Q
-### Definition
-
-> \[[i]\] [dip] [i]
-
### Discussion
This combinator may seem trivial but it comes in handy.
@@ -352,8 +308,6 @@ This combinator may seem trivial but it comes in handy.
## bool
-Function
-
Convert the item on the top of the stack to a Boolean value.
### Discussion
@@ -384,10 +338,6 @@ Use a Boolean value to select and run one of two quoted programs.
T
-### Definition
-
-> [rolldown] [choice] [i]
-
### Discussion
This is one of the fundamental operations (although it can be defined in
@@ -401,50 +351,35 @@ terms of [choice] as above). The more common "if..then..else" construct
[select]
---------------
-
-## •
-
-See [id](#id).
------------------------------------------------------------------------
## ccccons
-Function
-
a b c d [...] ccccons
---------------------------
[a b c d ...]
Do [cons] four times.
-### Definition
-
-> [ccons] [ccons]
-
### Crosslinks
-[ccons] [cons] [times]
+[ccons]
+[cons]
+[times]
--------------------
## ccons
-Function
-
a b [...] ccons
---------------------
[a b ...]
Do [cons] two times.
-### Definition
-
-> [cons] [cons]
-
### Crosslinks
[cons]
@@ -455,8 +390,6 @@ Do [cons] two times.
## choice
-Function
-
Use a Boolean value to select one of two items.
a b false choice
@@ -467,10 +400,6 @@ Use a Boolean value to select one of two items.
---------------------
b
-### Definition
-
-> \[[pop]\] \[[popd]\] [branch]
-
### Discussion
It's a matter of taste whether you implement this in terms of [branch] or
@@ -493,14 +422,8 @@ See [xor](#xor).
## clear
-Function
-
Clear everything from the stack.
-### Definition
-
-> [stack] [bool] \[[pop] [stack] [bool]\] [loop]
-
### Crosslinks
[stack]
@@ -553,10 +476,6 @@ Run two programs in parallel, consuming two additional items, and put their resu
--------------------------
... a b
-### Definition
-
-> [cleave] [popdd]
-
### Discussion
Like [cleave] but consumes an additional item from the stack.
@@ -606,11 +525,6 @@ Or even:
[GL] [E] over cmp
-### Crosslinks
-
-TODO: link to tree notebooks where this was used.
-
-
------------------------------------------------------------------------
## codi
@@ -624,10 +538,6 @@ Take a quoted program from the stack, [cons] the next item onto it, then
--------------------
b . F a
-### Definition
-
-> [cons] [dip]
-
### Discussion
This is one of those weirdly specific functions that turns out to be
@@ -648,10 +558,6 @@ Combinator
This is part of the [make_generator] function. You would not use this
combinator directly.
-### Definition
-
-> [codi] [reco]
-
### Discussion
See [make_generator] and the
@@ -668,8 +574,6 @@ as well as
## concat
-Function
-
Concatinate two lists.
[a b c] [d e f] concat
@@ -739,8 +643,6 @@ expressions, e.g.:
## cons
-Function
-
Given an item and a list, append the item to the list to make a new list.
a [...] cons
@@ -765,11 +667,6 @@ Combinator
Specialist function (that means I forgot what it does and why.)
-### Definition
-
-> [dip] [infrst]
-
-
------------------------------------------------------------------------
## dipdd
@@ -862,8 +759,6 @@ pending expression (not counting modifications to the dictionary.)
## disenstacken
-Function
-
The `disenstacken` function expects a list on top of the stack and makes
that the stack discarding the rest of the stack.
@@ -871,10 +766,6 @@ that the stack discarding the rest of the stack.
--------------------------------
6 5 4
-### Definition
-
-> \[[clear]\] [dip] [reverse] [unstack](#unstack)
-
### Discussion
Note that the order of the list is not changed, it just looks that way
@@ -885,7 +776,6 @@ printed with the top or head on the left.
[enstacken]
[stack]
-[unstack](#unstack)
--------------
@@ -899,8 +789,6 @@ See [floordiv](#floordiv).
## divmod
-Function
-
x y divmod
------------------
q r
@@ -909,17 +797,10 @@ Function
Invariant: `qy + r = x`.
-### Definition
-
-> \[[floordiv]\] \[[mod]\] [clop]
-
-
------------------------------------------------------------------------
## down_to_zero
-Function
-
Given a number greater than zero put all the Natural numbers (including
zero) less than that onto the stack.
@@ -929,10 +810,6 @@ zero) less than that onto the stack.
--------------------
3 2 1 0
-### Definition
-
-> \[0 \>\] \[[dup] [--]\] [while]
-
### Crosslinks
[range]
@@ -942,8 +819,6 @@ zero) less than that onto the stack.
## drop
-Function
-
Expects an integer and a quote on the stack and returns the quote with n
items removed off the top.
@@ -953,10 +828,6 @@ items removed off the top.
----------------------
[c d]
-### Definition
-
-> \[[rest]\] [times]
-
### Crosslinks
[take]
@@ -966,18 +837,12 @@ items removed off the top.
## dupdd
-Function
-
[dup] the third item down on the stack.
a b c dupdd
-----------------
a a b c
-### Definition
-
-> \[[dup]\] [dipd]
-
### Crosslinks
[dup]
@@ -998,10 +863,6 @@ Run a copy of program `F` under the next item down on the stack.
-------------------
F a [F]
-### Definition
-
-> [dup] [dipd]
-
### Crosslinks
[dupdip]
@@ -1019,10 +880,6 @@ Apply a function `F` and [dup] the item under it on the stack.
------------------
a F a
-### Definition
-
-> [dupd] [dip]
-
### Derivation
a [F] dupdip
@@ -1045,18 +902,12 @@ A very common and useful combinator.
## dupd
-Function
-
[dup] the second item down on the stack.
a b dupd
--------------
a a b
-### Definition
-
-> \[[dup]\] [dip]
-
### Crosslinks
[dup]
@@ -1069,8 +920,6 @@ Function
## dup
-Function
-
"Dup"licate the top item on the stack.
a dup
@@ -1089,8 +938,6 @@ Function
## enstacken
-Function
-
Put the stack onto the stack replacing the contents of the stack.
... a b c enstacken
@@ -1098,10 +945,6 @@ Put the stack onto the stack replacing the contents of the stack.
[c b a ...]
-### Definition
-
-> [stack] \[[clear]\] [dip]
-
### Discussion
This is a destructive version of [stack]. See the note under
@@ -1110,7 +953,6 @@ This is a destructive version of [stack]. See the note under
### Crosslinks
[stack]
-[unstack]
[disenstacken]
@@ -1118,8 +960,6 @@ This is a destructive version of [stack]. See the note under
## eq
-Function
-
Compare the two items on the top of the stack for equality and replace
them with a Boolean value.
@@ -1156,8 +996,6 @@ See [ne](#ne).
## !-
-Function
-
Not negative.
@@ -1171,10 +1009,6 @@ Not negative.
true
-### Definition
-
- 0 \>=
-
### Discussion
Return a Boolean value indicating if a number is greater than or equal to
@@ -1185,18 +1019,12 @@ zero.
## first
-Function
-
Replace a list with its first item.
[a ...]
--------------
a
-### Definition
-
-> [uncons] [pop]
-
### Crosslinks
[second]
@@ -1209,18 +1037,12 @@ Replace a list with its first item.
## first_two
-Function
-
Replace a list with its first two items.
[a b ...] first_two
-------------------------
a b
-### Definition
-
-> [uncons] [first]
-
### Crosslinks
[first]
@@ -1234,8 +1056,6 @@ Replace a list with its first two items.
## flatten
-Function
-
Given a list of lists, concatinate them.
### Example
@@ -1244,10 +1064,6 @@ Given a list of lists, concatinate them.
-------------------------------------
[1 2 3 [4] 5 6 7]
-### Definition
-
-> [\<\{\}] \[[concat]\] [step]
-
### Discussion
Note that only one "level" of lists is flattened. In the example above
@@ -1280,8 +1096,6 @@ Note that only one "level" of lists is flattened. In the example above
## floordiv
-Function
-
I don't know why this is called "floor" div, I think it rounds its
result down (not towards zero or up.)
@@ -1303,8 +1117,6 @@ for Thun gets nailed down.
## floor
-Function
-
Return the largest integer \<= x.
### Discussion
@@ -1325,10 +1137,6 @@ Run two quoted programs in parallel and replace them with their results.
----------------------
... f g
-### Definition
-
-> \[[i]\] [app2]
-
### Discussion
The basic parallelism combinator, the two programs are run independently.
@@ -1344,18 +1152,12 @@ The basic parallelism combinator, the two programs are run independently.
## fourth
-Function
-
Replace a list with its fourth item.
[a b c d ...] fourth
--------------------------
d
-### Definition
-
-> [rest] [third]
-
### Crosslinks
[first]
@@ -1368,8 +1170,6 @@ Replace a list with its fourth item.
## gcd2
-Function
-
Compiled GCD function.
### Discussion
@@ -1385,15 +1185,9 @@ See [gcd].
## gcd
-Function
-
Take two integers from the stack and replace them with their Greatest
Common Denominator.
-### Definition
-
-> true \[[tuck] [mod] [dup] 0 [>]\] [loop] [pop]
-
### Discussion
Euclid's Algorithm
@@ -1403,8 +1197,6 @@ Euclid's Algorithm
## ge
-Function
-
Greater-than-or-equal-to comparison of two numbers.
a b ge
@@ -1434,16 +1226,12 @@ Combinator
---------------------------------------------------------------------
[if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte
-### Definition
+### Discussion
-> \[\[[genrec]\] [ccccons]\] [nullary] [swons] [concat] [ifte]
-
-(Note that this definition includes the `genrec` symbol itself, it is
+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
-only self-referential definition.)
-
-### Discussion
+only self-referential definition.
See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursion_Combinators.html).
@@ -1498,8 +1286,6 @@ Tail recursive functions are those where `R2` is the `i` combinator:
## getitem
-Function
-
Expects an integer and a quote on the stack and returns the item at the
nth position in the quote counting from 0.
@@ -1509,10 +1295,6 @@ nth position in the quote counting from 0.
-------------------------
c
-### Definition
-
-> [drop] [first]
-
### Discussion
If the number isn't a valid index into the quote `getitem` will cause
@@ -1545,8 +1327,6 @@ implementation-dependant.)
## grabN
-Function
-
Expect a number on the top of the stack and [cons] that many items from under it onto a new list.
### Example
@@ -1555,16 +1335,10 @@ Expect a number on the top of the stack and [cons] that many items from under it
-----------------------
a b [c d e]
-### Definition
-
-> [\<\{\}] \[[cons]\] [times]
-
------------------------------------------------------------------------
## grba
-Function
-
A weird function used in [app2] that does this:
... 1 2 3 4 5 grba
@@ -1573,10 +1347,6 @@ A weird function used in [app2] that does this:
It grabs the stack under the top item, and substitutes it for the second item down on the stack.
-### Definition
-
-> \[[stack] [popd]\] [dip]
-
### Discussion
This function "grabs" an item from the stack along with a copy of the stack.
@@ -1611,8 +1381,6 @@ See [gt](#gt).
## gt
-Function
-
Greater-than comparison of two numbers.
a b gt
@@ -1633,8 +1401,6 @@ Greater-than comparison of two numbers.
## help
-Function
-
Accepts a quoted symbol on the top of the stack and prints its
documentation.
@@ -1665,16 +1431,10 @@ See [sub](#sub).
## hypot
-Function
-
x y hypot
---------------------------
sqrt(sqr(x) + sqr(y))
-### Definition
-
-> \[[sqr]\] [ii] [+] [sqrt]
-
### Discussion
This is another function that has to wait on the numeric tower.
@@ -1688,8 +1448,6 @@ This is another function that has to wait on the numeric tower.
## id
-Function
-
The identity function.
### Discussion
@@ -1708,10 +1466,6 @@ If-Then-Else combinator, a common and convenient specialization of [branch].
---------------------------------------
[if] nullary [else] [then] branch
-### Definition
-
-> \[[nullary]\] [dipd] [swap] [branch]
-
### Crosslinks
[branch]
@@ -1731,10 +1485,6 @@ top item, then again with the top item.
------------------
... Q a Q
-### Definition
-
-> \[[dip]\] [dupdip] [i]
-
### Example
It's a little tricky to understand how this works so here's an example trace:
@@ -1798,10 +1548,6 @@ the list as its stack. Does not affect the stack (below the list.)
---------------------------------
c b a Q [z y x ...] swaack
-### Definition
-
-> [swons] [swaack] \[[i]\] [dip] [swaack]
-
... [a b c] [F] swons swaack [i] dip swaack
... [[F] a b c] swaack [i] dip swaack
@@ -1833,11 +1579,6 @@ Combinator
Does [infra] and then extracts the [first] item from the resulting list.
-### Definition
-
-> [infra] [first]
-
-
------------------------------------------------------------------------
## inscribe
@@ -1860,8 +1601,6 @@ know what you're doing.
## le
-Function
-
Less-Than-or-Equal-to comparison of the two items on the top of the
stack, replacing them with a Boolean value.
@@ -1897,18 +1636,12 @@ See [ne](#ne).
## <{}
-Function
-
... a <{}
----------------
... [] a
-### Definition
-
- [] swap
-
### Discussion
Tuck an empty list just under the first item on the stack.
@@ -1922,19 +1655,12 @@ Tuck an empty list just under the first item on the stack.
## <<{}
-Function
-
... b a <{}
-----------------
... [] b a
-### Definition
-
- [] rollup
-
-
### Discussion
Tuck an empty list just under the first two items on the stack.
@@ -1999,8 +1725,6 @@ Just as [branch] has it's more common and convenient form [ifte],
## lshift
-Function
-
[Logical Left-Shift](https://en.wikipedia.org/wiki/Logical_shift)
a n lshift
@@ -2015,8 +1739,6 @@ Function
## lt
-Function
-
Less-Than comparison of the two items on the top of the
stack, replacing them with a Boolean value.
@@ -2038,8 +1760,6 @@ stack, replacing them with a Boolean value.
## make_generator
-Function
-
Given an initial state value and a quoted generator function build a
generator quote.
@@ -2059,10 +1779,6 @@ And then:
---------------------------------------------
230 231 232 233 234
-### Definition
-
-> \[[codireco]\] [ccons]
-
### Discussion
See the ["Using `x` to Generate Values" notebook](https://joypy.osdn.io/notebooks/Generator_Programs.html#an-interesting-variation).
@@ -2106,8 +1822,6 @@ parallelism combinator due to the "pure" nature of the language.
## max
-Function
-
Given a list find the maximum.
### Example
@@ -2127,8 +1841,6 @@ Given a list find the maximum.
## min
-Function
-
Given a list find the minimum.
### Example
@@ -2148,8 +1860,6 @@ Given a list find the minimum.
## mod
-Function
-
Return the remainder of `a` divided by `b`.
a b mod
@@ -2173,8 +1883,6 @@ See [mod](#mod).
## mul
-Function
-
Multiply two numbers.
a b mul
@@ -2191,24 +1899,16 @@ Multiply two numbers.
## neg
-Function
-
Invert the sign of a number.
a neg
-----------
-a
-### Definition
-
-> 0 [swap] [-]
-
------------------------------------------------------------------------
## ne
-Function
-
Not-Equal comparison of the two items on the top of the
stack, replacing them with a Boolean value.
@@ -2230,8 +1930,6 @@ stack, replacing them with a Boolean value.
## not
-Function
-
Like [bool] but convert the item on the top of the stack to the inverse
Boolean value.
@@ -2243,10 +1941,6 @@ Boolean value.
---------------
true
-### Definition
-
-> [bool] \[true\] \[false\] [branch]
-
### Crosslinks
[bool]
@@ -2256,18 +1950,12 @@ Boolean value.
## nulco
-Function
-
Take the item on the top of the stack and [cons] it onto `[nullary]`.
[F] nulco
-------------------
[[F] nullary]
-### Definition
-
-> \[[nullary]\] [cons]
-
### Discussion
Helper function for [\|\|] and [&&].
@@ -2275,7 +1963,7 @@ Helper function for [\|\|] and [&&].
### Crosslinks
[&&]
-[\|\|]
+[||]
--------------------
@@ -2291,10 +1979,6 @@ item of the result on the stack.
---------------------
... a
-### Definition
-
-> \[[stack]\] [dip] [infra] [first]
-
### Example
... [P] nullary
@@ -2321,8 +2005,6 @@ program.)
## of
-Function
-
Like [getitem] but [swap]s the order of arguments.
### Example
@@ -2331,10 +2013,6 @@ Like [getitem] but [swap]s the order of arguments.
--------------------
c
-### Definition
-
-> [swap] [getitem]
-
### Crosslinks
[getitem]
@@ -2344,8 +2022,6 @@ Like [getitem] but [swap]s the order of arguments.
## or
-Function
-
Logical bit-wise OR.
### Crosslinks
@@ -2358,8 +2034,6 @@ Logical bit-wise OR.
## over
-Function
-
[dup] the second item on the stack `over` the first.
a b over
@@ -2407,10 +2081,6 @@ rest of the stack.)
-------------------------------
5 7 [12 -2 35 0 5]
-### Definition
-
-> \[[i]\] [map]
-
### Discussion
A specialization of [map] that runs a list of functions in parallel (if
@@ -2453,35 +2123,22 @@ See [succ](#succ).
## pm
-Function
-
Plus or minus. Replace two numbers with their sum and difference.
a b pm
-----------------
(a+b) (a-b)
-### Definition
-
-> \[+\] \[-\] [clop]
-
-
------------------------------------------------------------------------
## popdd
-Function
-
[pop] the third item on the stack.
a b c popdd
-----------------
b c
-### Definition
-
-> [rolldown] [pop]
-
### Crosslinks
[pop]
@@ -2496,18 +2153,12 @@ Function
## popd
-Function
-
[pop] the second item down on the stack.
a b popd
--------------
b
-### Definition
-
-> [swap] [pop]
-
### Crosslinks
[pop]
@@ -2522,8 +2173,6 @@ Function
## pop
-Function
-
Pop the top item from the stack and discard it.
a pop
@@ -2543,16 +2192,10 @@ Pop the top item from the stack and discard it.
## popopdd
-Function
-
a b c d popopdd
---------------------
c d
-### Definition
-
-> \[[popop]\] [dipd]
-
### Crosslinks
[pop]
@@ -2567,18 +2210,12 @@ Function
## popopd
-Function
-
[pop] the second and third items from the stack.
a b c popopd
------------------
c
-### Definition
-
-> [rollup] [popop]
-
### Crosslinks
[pop]
@@ -2593,17 +2230,11 @@ Function
## popop
-Function
-
[pop] two items from the stack.
a b popop
---------------
-### Definition
-
-> [pop] [pop]
-
### Crosslinks
[pop]
@@ -2618,17 +2249,11 @@ Function
## popopop
-Function
-
[pop] three items from the stack.
a b c popopop
-------------------
-### Definition
-
-> [pop] [popop]
-
### Crosslinks
[pop]
@@ -2643,8 +2268,6 @@ Function
## pow
-Function
-
Take two numbers `a` and `n` from the stack and raise `a` to the `n`th
power. (`n` is on the top of the stack.)
@@ -2663,14 +2286,8 @@ power. (`n` is on the top of the stack.)
## pred
-Function
-
Predecessor. Decrement TOS.
-### Definition
-
-> 1 -
-
### Crosslinks
[succ]
@@ -2725,8 +2342,6 @@ Simple and useful specialization of the [genrec] combinator from the
## product
-Function
-
Just as [sum] sums a list of numbers, this function multiplies them
together.
@@ -2744,14 +2359,8 @@ Or,
## ?
-Function
-
Is the item on the top of the stack "truthy"?
-### Definition
-
-> [dup](#dup) [bool](#bool)
-
### Discussion
You often want to test the truth value of an item on the stack without
@@ -2766,18 +2375,12 @@ consuming the item.
## quoted
-Function
-
"Quote D" Wrap the second item on the stack in a list.
a b quoted
----------------
[a] b
-### Definition
-
-> \[[unit]\] [dip]
-
### Discussion
This comes from the original Joy stuff.
@@ -2791,8 +2394,6 @@ This comes from the original Joy stuff.
## range
-Function
-
Expect a number `n` on the stack and replace it with a list:
`[(n-1)...0]`.
@@ -2806,10 +2407,6 @@ Expect a number `n` on the stack and replace it with a list:
--------------
[]
-### Definition
-
-> \[0 \<=\] \[1 - [dup]\] [anamorphism]
-
### Discussion
If `n` is less than 1 the resulting list is empty.
@@ -2823,8 +2420,6 @@ If `n` is less than 1 the resulting list is empty.
## range_to_zero
-Function
-
Take a number `n` from the stack and replace it with a list
`[0...n]`.
@@ -2834,10 +2429,6 @@ Take a number `n` from the stack and replace it with a list
---------------------
[0 1 2 3 4 5]
-### Definition
-
-> [unit] \[[down_to_zero]\] [infra]
-
### Discussion
Note that the order is reversed compared to [range].
@@ -2852,18 +2443,12 @@ Note that the order is reversed compared to [range].
## reco
-Function
-
Replace the first item in a list with the item under it.
a [b ...] reco
--------------------
[a ...]
-### Definition
-
-> [rest] [cons]
-
### Crosslinks
[codireco]
@@ -2888,8 +2473,6 @@ See [mod](#mod).
## remove
-Function
-
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.
@@ -2907,8 +2490,6 @@ See the ["Remove Function" notebook](https://osdn.net/projects/joypy/scm/git/Thu
## rest
-Function
-
[a ...] rest
------------------
[...]
@@ -2923,8 +2504,6 @@ Function
## reverse
-Function
-
Reverse the list on the top of the stack.
### Example
@@ -2933,25 +2512,15 @@ Reverse the list on the top of the stack.
---------------------
[3 2 1]
-### Definition
-
-> [\<\{\}] [shunt]
-
------------------------------------------------------------------------
## rolldown
-Function
-
a b c rolldown
--------------------
b c a
-### Definition
-
-> [swapd] [swap]
-
### Crosslinks
[rollup]
@@ -2975,16 +2544,10 @@ See [rolldown](#rolldown).
## rollup
-Function
-
a b c rollup
------------------
c a b
-### Definition
-
-> [swap] [swapd]
-
### Crosslinks
[rolldown]
@@ -2994,8 +2557,6 @@ Function
## round
-Function
-
Round a number to a given precision in decimal digits.
### Discussion
@@ -3008,14 +2569,9 @@ down.
## rrest
-Function
-
[a b ...] rrest
---------------------
[...]
-### Definition
-
-> [rest] [rest]
### Crosslinks
@@ -3026,8 +2582,6 @@ Function
## rshift
-Function
-
[Logical Right-Shift](https://en.wikipedia.org/wiki/Logical_shift)
a n rshift
@@ -3042,8 +2596,6 @@ Function
## run
-Function
-
Run a quoted program in a list.
### Example
@@ -3052,25 +2604,14 @@ Run a quoted program in a list.
-----------------
[3]
-### Definition
-
-> [\<\{\}] [infra]
-
-
------------------------------------------------------------------------
## second
-Function
-
[a b ...] second
----------------------
b
-### Definition
-
-> [rest] [first]
-
### Crosslinks
[first]
@@ -3082,8 +2623,6 @@ Function
## select
-Function
-
Use a Boolean value to select one of two items from a sequence. :
[a b] false select
@@ -3107,8 +2646,6 @@ The sequence can contain more than two items but not fewer.
## sharing
-Function
-
Print redistribution information.
### Discussion
@@ -3125,8 +2662,6 @@ printing out the GPL notice.
## shift
-Function
-
Move the top item from one list to another.
### Example
@@ -3135,10 +2670,6 @@ Move the top item from one list to another.
---------------------------
[a x y z] [b c]
-### Definition
-
-> [uncons] \[[swons]\] [dip]
-
### Crosslinks
[shunt]
@@ -3148,8 +2679,6 @@ Move the top item from one list to another.
## shunt
-Function
-
Like [concat] but [reverse] the top list into the second.
### Example
@@ -3158,10 +2687,6 @@ Like [concat] but [reverse] the top list into the second.
---------------------------
[f e d a b c]
-### Definition
-
-> \[[swons]\] [step]
-
### Discussion
This is more efficient than [concat] so prefer it if you don't need to
@@ -3178,8 +2703,6 @@ preserve order.
## size
-Function
-
Replace a list with its size.
### Example
@@ -3188,10 +2711,6 @@ Replace a list with its size.
------------------------
3
-### Definition
-
-> \[[pop] [++]\] [step_zero]
-
--------------
@@ -3218,8 +2737,6 @@ See [floordiv](#floordiv).
## sort
-Function
-
Given a list return it sorted.
### Example
@@ -3233,8 +2750,6 @@ Given a list return it sorted.
## spiral_next
-Function
-
Example code.
### Discussion
@@ -3246,8 +2761,6 @@ See the ["Square Spiral Example Joy Code" notebook](https://joypy.osdn.io/notebo
## split_at
-Function
-
Split a list (second on the stack) at the position given by the number on
the top of the stack.
@@ -3257,10 +2770,6 @@ the top of the stack.
--------------------------------
[5 6 7] [4 3 2 1]
-### Definition
-
-> \[[drop]\] \[[take]\] [clop]
-
### Discussion
Take a list and a number `n` from the stack, take `n` items from the top
@@ -3276,8 +2785,6 @@ on the top of the stack.
## split_list
-Function
-
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.
@@ -3286,10 +2793,6 @@ list.
----------------------------------
[1 2 3 4] [5 6 7]
-### Definition
-
-> \[[take] [reverse]\] \[[drop]\] [clop]
-
### Discussion
Compare with [split_at]. This function does extra work to ensure that
@@ -3304,19 +2807,12 @@ Compare with [split_at]. This function does extra work to ensure that
## sqr
-Function
-
Square the number on the top of the stack.
n sqr
------------
n²
-### Definition
-
-> [dup] [mul]
-
-
------------------------------------------------------------------------
## sqrt
@@ -3335,8 +2831,6 @@ Another "numeric tower" hatch...
## stackd
-Function
-
Grab the stack under the top item and put it onto the stack.
### Example
@@ -3345,27 +2839,17 @@ Grab the stack under the top item and put it onto the stack.
------------------------
... 1 2 [2 1 ...] 3
-### Definition
-
-> \[[stack]\] [dip]
-
------------------------------------------------------------------------
## stack
-Function
-
Put the stack onto the stack.
... c b a stack
---------------------------
... c b a [a b c ...]
-### Definition
-
-> \[\] [swaack] [dup] [swaack] [first]
-
### Discussion
This function forms a pair with [unstack], and together they form the
@@ -3373,7 +2857,6 @@ complement to the "destructive" pair [enstacken] and [disenstacken].
### Crosslinks
-[unstack]
[enstacken]
[disenstacken]
@@ -3421,10 +2904,6 @@ Like [step] but with 0 as the initial value.
-------------------------
0 [...] [F] step
-### Definition
-
-> 0 [roll>] [step]
-
### Discussion
[size] and [sum] can both be defined in terms of this specialization of
@@ -3439,8 +2918,6 @@ Like [step] but with 0 as the initial value.
## stuncons
-Function
-
Take the [stack] and [uncons] the top item.
### Example
@@ -3449,17 +2926,10 @@ Take the [stack] and [uncons] the top item.
--------------------
1 2 3 3 [2 1]
-### Definition
-
-> [stack] [uncons]
-
-
------------------------------------------------------------------------
## stununcons
-Function
-
Take the [stack] and [uncons] the top two items.
### Example
@@ -3468,10 +2938,6 @@ Take the [stack] and [uncons] the top two items.
----------------------
1 2 3 3 2 [1]
-### Definition
-
-> [stack] [uncons] [uncons]
-
### Crosslinks
[stuncons]
@@ -3481,8 +2947,6 @@ Take the [stack] and [uncons] the top two items.
## sub
-Function
-
Subtract the number on the top of the stack from the number below it.
a b sub
@@ -3498,14 +2962,8 @@ Subtract the number on the top of the stack from the number below it.
## succ
-Function
-
Successor. Increment TOS.
-### Definition
-
-> 1 +
-
### Crosslinks
[pred]
@@ -3525,10 +2983,6 @@ Given a quoted sequence of numbers return the sum.
---------------------
15
-### Definition
-
-> \[+\] [step_zero]
-
### Crosslinks
[size]
@@ -3538,8 +2992,6 @@ Given a quoted sequence of numbers return the sum.
## swaack
-Function
-
Swap stack. Take a list from the top of the stack, replace the stack
with the list, and put the old stack onto it.
@@ -3563,18 +3015,12 @@ definition of [infra].
## swapd
-Function
-
Swap the second and third items on the stack.
a b c swapd
-----------------
b a c
-### Definition
-
-> \[[swap]\] [dip]
-
### Crosslinks
[over]
@@ -3585,8 +3031,6 @@ Swap the second and third items on the stack.
## swap
-Function
-
Swap the top two items on the stack.
a b swap
@@ -3602,14 +3046,8 @@ Swap the top two items on the stack.
## swoncat
-Function
-
[concat] two lists, but [swap] the lists first.
-### Definition
-
-> [swap] [concat]
-
### Crosslinks
[concat]
@@ -3619,18 +3057,12 @@ Function
## swons
-Function
-
Like [cons] but [swap] the item and list.
[...] a swons
-------------------
[a ...]
-### Definition
-
-> [swap] [cons]
-
------------------------------------------------------------------------
@@ -3640,10 +3072,6 @@ Combinator
A specialization of the [genrec] combinator.
-### Definition
-
-> \[[i]\] [genrec]
-
### Discussion
Some recursive functions do not need to store additional data or pending
@@ -3662,8 +3090,6 @@ See the [Recursion Combinators notebook](https://joypy.osdn.io/notebooks/Recursi
## take
-Function
-
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.
@@ -3671,11 +3097,6 @@ with just the top `n` items in reverse order.
----------------------
[b a]
-### Definition
-
-> [\<\<\{\}] \[[shift]\] [times] [pop]
-
-
--------------------
## ternary
@@ -3689,10 +3110,6 @@ item of the result on the stack.
-------------------------
... a
-### Definition
-
-> [binary] [popd]
-
### Discussion
Runs any other quoted function and returns its first result while
@@ -3709,16 +3126,10 @@ consuming exactly three items from the stack.
## third
-Function
-
[a b c ...] third
-----------------------
c
-### Definition
-
-> [rest] [second]
-
### Crosslinks
[first]
@@ -3748,10 +3159,6 @@ program `n` times.
------------------------------------- w/ n > 1
... . Q (n-1) [Q] times
-### Definition
-
-> \[\-- dip\] cons \[swap\] infra \[0 \>\] swap while pop :
-
### Discussion
@@ -3760,13 +3167,13 @@ This works by building a little [while] program and running it:
1 3 [++] • [-- dip] cons [swap] infra [0 >] swap while pop
1 3 [++] [-- dip] • cons [swap] infra [0 >] swap while pop
1 3 [[++] -- dip] • [swap] infra [0 >] swap while pop
- 1 3 [[++] -- dip] [swap] • infra [0 >] swap while pop
+ 1 3 [[++] -- dip] [swap] • infra [0 >] swap while pop
dip -- [++] • swap [3 1] swaack [0 >] swap while pop
dip [++] -- • [3 1] swaack [0 >] swap while pop
dip [++] -- [3 1] • swaack [0 >] swap while pop
1 3 [-- [++] dip] • [0 >] swap while pop
- 1 3 [-- [++] dip] [0 >] • swap while pop
- 1 3 [0 >] [-- [++] dip] • while pop
+ 1 3 [-- [++] dip] [0 >] • swap while pop
+ 1 3 [0 >] [-- [++] dip] • while pop
This is a common pattern in Joy. You accept some parameters from the
stack which typically include qouted programs and use them to build
@@ -3785,8 +3192,6 @@ See [bool](#bool).
## tuck
-Function
-
[dup] the item on the top of the stack under the second item on the
stack.
@@ -3794,10 +3199,6 @@ stack.
--------------
b a b
-### Definition
-
-> [dup] \[[swap]\] [dip]
-
### Crosslinks
[over]
@@ -3816,10 +3217,6 @@ item of the result on the stack.
---------------------
... a
-### Definition
-
-> [nullary] [popd]
-
### Discussion
Runs any other quoted function and returns its first result while
@@ -3836,8 +3233,6 @@ consuming exactly one item from the stack.
## uncons
-Function
-
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.
@@ -3858,8 +3253,6 @@ This is the inverse of [cons].
## unique
-Function
-
Given a list remove duplicate items.
@@ -3867,17 +3260,10 @@ Given a list remove duplicate items.
## unit
-Function
-
a unit
------------
[a]
-### Definition
-
-> \[\] [cons]
-
-
------------------------------------------------------------------------
## unquoted
@@ -3892,10 +3278,6 @@ Unquote (using [i]) the list that is second on the stack.
--------------------------
1 2 3 4 5
-### Definition
-
-> \[[i]\] [dip]
-
### Crosslinks
[unit]
@@ -3905,16 +3287,10 @@ Unquote (using [i]) the list that is second on the stack.
## unswons
-Function
-
[a ...] unswons
---------------------
[...] a
-### Definition
-
-> [uncons] [swap]
-
------------------------------------------------------------------------
@@ -3925,10 +3301,6 @@ Combinator
Short-circuiting Boolean OR
-### Definition
-
-> [nulco](#nulco) \[[nullary](#nullary)\] [dip](#dip) \[true\] [branch](#branch)
-
### Discussion
Accept two quoted programs, run the first and expect a Boolean value, if
@@ -3953,8 +3325,6 @@ stack.)
## void
-Function
-
True if the form on TOS is void otherwise False.
### Discussion
@@ -3968,8 +3338,6 @@ This represents a binary Boolean logical formula in the arithmetic of the
## warranty
-Function
-
Print warranty information.
@@ -3989,10 +3357,6 @@ and runs it [nullary].
--------------------- P -> true
F [P] [F] while
-### Definition
-
-> [swap] [nulco] [dupdipd] [concat] [loop]
-
### Crosslinks
[loop]
@@ -4002,8 +3366,6 @@ and runs it [nullary].
## words
-Function
-
Print all the words in alphabetical order.
### Discussion
@@ -4028,10 +3390,6 @@ the stack.
-----------
[F] F
-### Definition
-
- dup i
-
### Discussion
The simplest recursive pattern.
@@ -4046,8 +3404,6 @@ as well as
## xor
-Function
-
Logical bit-wise eXclusive OR.
### Crosslinks
@@ -4060,8 +3416,6 @@ Logical bit-wise eXclusive OR.
## zip
-Function
-
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.
diff --git a/docs/reference/to_html.py b/docs/reference/to_html.py
index 43be074..816b336 100644
--- a/docs/reference/to_html.py
+++ b/docs/reference/to_html.py
@@ -1,10 +1,68 @@
-import hashlib, re
+from collections import defaultdict
+import hashlib, re, sys
+sys.path.append('../../implementations/Python')
+import joy
from myhtml import HTML
TITLE = 'Thun Function Reference'
with open('Function-Reference.md') as f:
md = f.read()
+with open('../../implementations/defs.txt') as f:
+ defs = f.read()
+
+definitions = {
+ name: body
+ for name, body in (
+ defi.split(None, 1)
+ for defi in defs.splitlines()
+ )
+ if not name.startswith('_')
+ }
+
+def symbols_of(expression):
+ if isinstance(expression, str):
+ yield expression
+ return
+ if isinstance(expression, tuple) and expression:
+ yield from symbols_of(expression[0])
+ yield from symbols_of(expression[1])
+ return
+
+used_in = {
+ name: sorted(set(symbols_of(joy.text_to_expression(definitions[name]))))
+ for name in definitions
+ }
+
+used_by = defaultdict(list)
+for name in used_in:
+ for term in used_in[name]:
+ used_by[term].append(name)
+for el in used_by.values():
+ el.sort()
+
+
+def def_format(to, name):
+ try:
+ defi = definitions[name]
+ except KeyError:
+ return
+ to = to.div(class_='definition')
+ to.h3('Definition')
+ to = to.blockquote
+ start = 0
+ for match in re.finditer('[^ [\]]+', defi):
+ b, e = match.span()
+ if b != start:
+ to += defi[start:b]
+ foo = match.group()
+ anchor = anchors.get(foo, '')
+ to.a(foo, href='#' + anchor)
+ start = e
+ end = defi[start:]
+ if end:
+ to += end
+
k = re.split('^-+$', md, flags=re.MULTILINE)
#k = md.split('------------------------------------------------------------------------\n')
@@ -19,7 +77,6 @@ k = [section.splitlines() for section in k]
## s.remove(i) # cannot remove same i twice
##assert not s # one header per section
-
def anchor_for(name):
return 'function_' + (
name
@@ -46,6 +103,78 @@ combinators = set(
for name in combinators:
sections[name].remove('Combinator')
+# Crosslinks
+
+crosslinks = {}
+for name, section in sections.items():
+ try:
+ i = section.index('### Crosslinks')
+ except ValueError:
+ continue
+ crosslinks[name] = list(filter(None, section[i + 1:]))
+ del section[i:]
+
+discussions = {}
+for name, section in sections.items():
+ try:
+ i = section.index('### Discussion')
+ except ValueError:
+ continue
+ discussions[name] = list(filter(None, section[i + 1:]))
+ del section[i:]
+
+
+def add_crosslinks(to, name):
+ try:
+ links = crosslinks[name]
+ except KeyError:
+ return
+ to = to.div(class_='crosslinks')
+ to.h3('See Also')
+ first = True
+ for link in links:
+ if first:
+ first = not first
+ else:
+ to += ' '
+ match = re.match('\[(.+)\].*', link)
+ if not match:
+ print('!', link)
+ continue
+ link_to = match.group(1)
+ anchor = anchors[link_to]
+ to.a(link_to, href='#' + anchor, class_='func_name')
+
+
+def add_discussion(to, name):
+ try:
+ discussion = discussions[name]
+ except KeyError:
+ return
+ to = to.div(class_='discussion')
+ to.h3('Discussion')
+ to += ('\n'.join(discussion))
+
+
+def add_backlinks(to, name):
+ try:
+ links = used_by[name]
+ except KeyError:
+ return
+ if not links:
+ return
+ to = to.div(class_='backlinks')
+ to.h3('Used By')
+ first = True
+ for link_to in links:
+ if first:
+ first = not first
+ else:
+ to += ' '
+ anchor = anchors.get(link_to, '')
+ to.a(link_to, href='#' + anchor, class_='func_name')
+
+
doc = HTML()
with doc.head as h:
@@ -65,6 +194,7 @@ with doc.body as b:
ul.li.a(name, href='#' + anchor_for(name))
ul += ' '
for name, section in sorted(sections.items()):
+ b.hr
d = b.div
anchor_id = anchor_for(name)
title = d.h2(name, id=anchor_id, class_='func_name')
@@ -73,10 +203,16 @@ with doc.body as b:
if name in combinators:
d.p.span('combinator', class_='kind')
d.pre('\n'.join(section))
-
+ def_format(d, name)
+ add_discussion(d, name)
+ add_crosslinks(d, name)
+ add_backlinks(d, name)
html_string = '' + str(doc)
print(html_string, file=open('../html/FuncRef.html', 'w'))
#from bs4 import BeautifulSoup
#print(BeautifulSoup(html_string, 'html.parser').prettify())
+
+##import pprint
+##pprint.pprint(crosslinks)