diff --git a/docs/html/FuncRef.html b/docs/html/FuncRef.html index 9d7ed40..4918cc4 100644 --- a/docs/html/FuncRef.html +++ b/docs/html/FuncRef.html @@ -4,201 +4,46 @@ -
Version -10.0.0
Each function, combinator, or definition should be documented here.
See and.
+Function
+Return the absolute value of the argument.
++ +
Basis Function
+Add two numbers together: a + b.
+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.)
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.
@@ -373,15 +250,560 @@See and.
+Combinator
+Build a list of values from a generator program G and a stopping predicate P.
[P] [G] anamorphism
+-----------------------------------------
+ [P] [pop []] [G] [dip swons] genrec
++ ++
The range function generates a list of the integers from 0 to n - 1:
++[0 <=] [-- dup] anamorphism
+
See the Recursion Combinators notebook.
+Basis Function
+Logical bit-wise AND.
+“apply one”
+Combinator
+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 first result of the program.
+ ... x [Q] app1
+---------------------------------
+ ... [x ...] [Q] infra first
+This is the same effect as the unary 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 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
+++3 appN
+
See app2.
+Combinator
+Like app1 with any number of items.
+ ... xN ... x2 x1 x0 [Q] n . appN
+--------------------------------------
+ ... [xN ...] [Q] . infra first
+ ...
+ [x2 ...] [Q] infra first
+ [x1 ...] [Q] infra first
+ [x0 ...] [Q] infra first
++ ++
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.
See mul.
See getitem.
+Function
+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.
+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
++ ++
Runs any other quoted function and returns its first result while consuming exactly two items from the stack.
+Combinator
+Run two quoted programs
+ [P] [Q] b
+---------------
+ P Q
++ ++
This combinator may seem trivial but it comes in handy.
+Basis Function
+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.
Basis Combinator
+Use a Boolean value to select and run one of two quoted programs.
+ false [F] [T] branch
+--------------------------
+ F
+
+ true [F] [T] branch
+-------------------------
+ T
++ ++
This is one of the fundamental operations (although it can be defined in terms of choice as above). The more common “if..then..else” construct ifte adds a predicate function that is evaluated nullary.
+See id.
Function
+ a b c d [...] ccccons
+---------------------------
+ [a b c d ...]
+Do cons four times.
++ ++
Function
+ a b [...] ccons
+---------------------
+ [a b ...]
+Do cons two times.
++ ++
Basis Function
+Use a Boolean value to select one of two items.
+ a b false choice
+----------------------
+ a
+
+ a b true choice
+---------------------
+ b
++ ++
It’s a matter of taste whether you implement this in terms of branch or the other way around.
+See xor.
Basis Function
+Clear everything from the stack.
++ ++
Combinator
+Run two programs in parallel, consuming one additional item, and put their results on the stack.
+ ... x [A] [B] cleave
+------------------------
+ ... a b
++ ++
1 2 3 [+] [-] cleave
+--------------------------
+ 1 2 5 -1
+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
+ G
+
+ a b [G] [E] [L] cmp
+------------------------- a = b
+ E
+
+ 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
+TODO: link to tree notebooks where this was used.
+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
++ ++
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 by Manfred von Thun.
Function
+Concatinate two lists.
+ [a b c] [d e f] concat
+----------------------------
+ [a b c d e f]
+first first_two flatten fourth getitem remove rest reverse rrest second shift shunt size sort split_at split_list swaack third zip
+Combinator
+This combinator works like a case statement. It expects a single quote on the stack that must contain zero or more condition quotes and a default quote. Each condition quote should contain a quoted predicate followed by the function expression to run if that predicate returns true. If no predicates return true the default function runs.
[
+ [ [Predicate0] Function0 ]
+ [ [Predicate1] Function1 ]
+ ...
+ [ [PredicateN] FunctionN ]
+ [Default]
+]
+cond
+It works by rewriting into a chain of nested ifte expressions, e.g.:
+ [[[B0] T0] [[B1] T1] [D]] cond
+-----------------------------------------
+ [B0] [T0] [[B1] [T1] [D] ifte] ifte
+Basis Function
+Given an item and a list, append the item to the list to make a new list.
+ a [...] cons
+------------------
+ [a ...]
+Cons is a venerable old function from Lisp. Its inverse operation is uncons.
+Combinator
+Specialist function (that means I forgot what it does and why.)
++ ++
Combinator
+Like dip but expects three items. :
+ ... z y x [Q] . dip
+-----------------------------
+ ... . Q z y x
+See dip.
+Combinator
+Like dip but expects two items.
+ ... y x [Q] . dipd
+-------------------------
+ ... . Q y x
+See dip.
+dip dipdd dupdip dupdipd infra
+Basis Combinator
+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 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 things about CPS is that the whole state is recorded in the stack and pending expression (not counting modifications to the dictionary.)
dipd dipdd dupdip dupdipd infra
+Function
+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.
+See floordiv.
+Function
+ x y divmod
+------------------
+ q r
+ (x/y) (x%y)
+Invariant: qy + r = x.
+ ++
Function
+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
++ ++
Function
+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]
++ ++
Function
+dup the third item down on the stack.
+ a b c dupdd
+-----------------
+ a a b c
++ ++
Combinator
+Run a copy of program F under the next item down on the stack.
a [F] dupdipd
+-------------------
+ F a [F]
++ ++
Combinator
+Apply a function F and dup the item under it on the stack.
a [F] dupdip
+------------------
+ a F a
++ ++
a [F] dupdip
+a [F] dupd dip
+a [F] [dup] dip dip
+a dup [F] dip
+a a [F] dip
+a F a
+A very common and useful combinator.
+Function
+dup the second item down on the stack.
+ a b dupd
+--------------
+ a a b
++ ++
Basis Function
+“Dup”licate the top item on the stack.
+ a dup
+-----------
+ a a
+Function
+Put the stack onto the stack replacing the contents of the stack.
+ ... a b c enstacken
+-------------------------
+ [c b a ...]
++ ++
This is a destructive version of stack. See the note under disenstacken about the apparent but illusory reversal of the stack.
+stack [unstack] disenstacken
+Basis Function
+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)
+See eq.
0 \>=
-Return a Boolean value indicating if a number is greater than or equal to zero.
-See gt.
-See ge.
-See rshift.
-See sub.
-See pred.
-See lt.
-See le.
-See ne.
-Function
- ... a <{}
-----------------
- ... [] a
-[] swap
-Tuck an empty list just under the first item on the stack.
-See lshift.
-Function
- ... b a <{}
------------------
- ... [] b a
-[] rollup
-Tuck an empty list just under the first two items on the stack.
-See mod.
-See add.
-See succ.
-Function
-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.
-See floordiv.
-See floordiv.
-See floordiv.
-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
-Function
-Return the absolute value of the argument.
-- --
Basis Function
-Add two numbers together: a + b.
-Combinator
-Build a list of values from a generator program G and a stopping predicate P.
[P] [G] anamorphism
------------------------------------------
- [P] [pop []] [G] [dip swons] genrec
-- --
The range function generates a list of the integers from 0 to n - 1:
--[0 <=] [-- dup] anamorphism
-
See the Recursion Combinators notebook.
-Basis Function
-Logical bit-wise AND.
-“apply one”
-Combinator
-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 first result of the program.
- ... x [Q] app1
----------------------------------
- ... [x ...] [Q] infra first
-This is the same effect as the unary 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 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
---3 appN
-
See app2.
-Combinator
-Like app1 with any number of items.
- ... xN ... x2 x1 x0 [Q] n . appN
---------------------------------------
- ... [xN ...] [Q] . infra first
- ...
- [x2 ...] [Q] infra first
- [x1 ...] [Q] infra first
- [x0 ...] [Q] infra first
-- --
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.
See getitem.
-Function
-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.
-Combinator
-Run two quoted programs
- [P] [Q] b
----------------
- P Q
-- --
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
-- --
Runs any other quoted function and returns its first result while consuming exactly two items from the stack.
-Basis Function
-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.
Basis Combinator
-Use a Boolean value to select and run one of two quoted programs.
- false [F] [T] branch
---------------------------
- F
-
- true [F] [T] branch
--------------------------
- T
-- --
This is one of the fundamental operations (although it can be defined in terms of choice as above). The more common “if..then..else” construct ifte adds a predicate function that is evaluated nullary.
-Function
- a b c d [...] ccccons
----------------------------
- [a b c d ...]
-Do cons four times.
-- --
Function
- a b [...] ccons
----------------------
- [a b ...]
-Do cons two times.
-- --
Basis Function
-Use a Boolean value to select one of two items.
- a b false choice
-----------------------
- a
-
- a b true choice
----------------------
- b
-- --
It’s a matter of taste whether you implement this in terms of branch or the other way around.
-Basis Function
-Clear everything from the stack.
-- --
Combinator
-Run two programs in parallel, consuming one additional item, and put their results on the stack.
- ... x [A] [B] cleave
-------------------------
- ... a b
-- --
1 2 3 [+] [-] cleave
---------------------------
- 1 2 5 -1
-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
- G
-
- a b [G] [E] [L] cmp
-------------------------- a = b
- E
-
- 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
-TODO: link to tree notebooks where this was used.
-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
-- --
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 by Manfred von Thun.
Function
-Concatinate two lists.
- [a b c] [d e f] concat
-----------------------------
- [a b c d e f]
-first first_two flatten fourth getitem remove rest reverse rrest second shift shunt size sort split_at split_list swaack third zip
-Combinator
-This combinator works like a case statement. It expects a single quote on the stack that must contain zero or more condition quotes and a default quote. Each condition quote should contain a quoted predicate followed by the function expression to run if that predicate returns true. If no predicates return true the default function runs.
[
- [ [Predicate0] Function0 ]
- [ [Predicate1] Function1 ]
- ...
- [ [PredicateN] FunctionN ]
- [Default]
-]
-cond
-It works by rewriting into a chain of nested ifte expressions, e.g.:
- [[[B0] T0] [[B1] T1] [D]] cond
------------------------------------------
- [B0] [T0] [[B1] [T1] [D] ifte] ifte
-Basis Function
-Given an item and a list, append the item to the list to make a new list.
- a [...] cons
-------------------
- [a ...]
-Cons is a venerable old function from Lisp. Its inverse operation is uncons.
-Combinator
-Specialist function (that means I forgot what it does and why.)
-- --
Basis Combinator
-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 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 things about CPS is that the whole state is recorded in the stack and pending expression (not counting modifications to the dictionary.)
dipd dipdd dupdip dupdipd infra
-Combinator
-Like dip but expects two items.
- ... y x [Q] . dipd
--------------------------
- ... . Q y x
-See dip.
-dip dipdd dupdip dupdipd infra
-Combinator
-Like dip but expects three items. :
- ... z y x [Q] . dip
------------------------------
- ... . Q z y x
-See dip.
-Function
-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.
-See floordiv.
-Function
- x y divmod
-------------------
- q r
- (x/y) (x%y)
-Invariant: qy + r = x.
- --
Function
-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
-- --
Function
-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]
-- --
Basis Function
-“Dup”licate the top item on the stack.
- a dup
------------
- a a
-Function
-dup the second item down on the stack.
- a b dupd
---------------
- a a b
- --
Function
-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
-- --
a [F] dupdip
-a [F] dupd dip
-a [F] [dup] dip dip
-a dup [F] dip
-a a [F] dip
-a F a
-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]
-- --
Function
-Put the stack onto the stack replacing the contents of the stack.
- ... a b c enstacken
--------------------------
- [c b a ...]
-- --
This is a destructive version of stack. See the note under disenstacken about the apparent but illusory reversal of the stack.
-stack [unstack] disenstacken
-Basis Function
-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)
-0 \>=
+Return a Boolean value indicating if a number is greater than or equal to zero.
Function
@@ -1065,11 +832,11 @@ a F a [a ...]
--------------
a
--
[a b ...] first_two
-------------------------
a b
--
first second third fourth rest
[[1 2] [3 [4] 5] [6 7]] flatten
-------------------------------------
[1 2 3 [4] 5 6 7]
-- +-
Note that only one “level” of lists is flattened. In the example above [4] is not unquoted.
concat first first_two fourth getitem remove rest reverse rrest second shift shunt size sort split_at split_list swaack third zip
Basis Function
-Return the largest integer <= x.
-This function doesn’t make sense (yet) to have because there are (as yet) only integers in the system.
-Basis Function
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)
-All the division commands need to be revisited when the “numeric tower” for Thun gets nailed down.
-Basis Function
+Return the largest integer <= x.
+This function doesn’t make sense (yet) to have because there are (as yet) only integers in the system.
+Combinator
Run two quoted programs in parallel and replace them with their results.
... [F] [G] fork
----------------------
... f g
--
The basic parallelism combinator, the two programs are run independently.
- [a b c d ...] fourth
--------------------------
d
--
Function
-Take two integers from the stack and replace them with their Greatest Common Denominator.
-- --
Euclid’s Algorithm
-Function
Compiled GCD function.
-See gcd.
-Function
+Take two integers from the stack and replace them with their Greatest Common Denominator.
++ ++
Euclid’s Algorithm
+Basis Function
Greater-than-or-equal-to comparison of two numbers.
@@ -1171,7 +938,7 @@ a F a -------------- Boolean (a >= b) - [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 only self-referential definition.)
See the Recursion Combinators notebook.
From “Recursion Theory and Joy” by Manfred von Thun:
@@ -1203,7 +970,7 @@ a F a-P == [I] [T] [R] tailrec == [I] [T] [R [P] i] ifte == [I] [T] [R P] ifteCrosslinks
+Crosslinks
getitem
@@ -1213,13 +980,13 @@ a F a-[a b c d] 2 getitem ------------------------- cDefinition
+Definition
-Discussion
+Discussion
If the number isn’t a valid index into the quote
-getitemwill cause some sort of problem (the exact nature of which is implementation-dependant.)Crosslinks
+Crosslinks
concat first first_two flatten fourth remove rest reverse rrest second shift shunt size sort split_at split_list swaack third zip
grabN
@@ -1229,9 +996,9 @@ a F a-a b c d e 3 grabN ----------------------- a b [c d e]Definition
+Definition
- +
grba
@@ -1241,15 +1008,24 @@ a F a ------------------------------- ... 1 2 3 [4 3 2 1 ...] 5It grabs the stack under the top item, and substitutes it for the second item down on the stack.
-Definition
+Definition
-Discussion
+Discussion
This function “grabs” an item from the stack along with a copy of the stack. It’s part of the app2 definition.
-Crosslinks
+Crosslinks
+>=
+See ge.
+
+>>
+See rshift.
+
+>
+See gt.
+
gt
Basis Function
Greater-than comparison of two numbers.
@@ -1257,7 +1033,7 @@ a F a -------------- Boolean (a > b) -Crosslinks
+Crosslinks
help
@@ -1265,36 +1041,33 @@ a F aAccepts a quoted symbol on the top of the stack and prints its documentation.
-[foo] help ----------------Discussion
+Discussion
Technically this is equivalent to
pop, but it will only work if the item on the top of the stack is a quoted symbol.
+–
+See pred.
+
+-
+See sub.
+
hypot
Function
-x y hypot --------------------------- sqrt(sqr(x) + sqr(y))Definition
+Definition
-Discussion
+Discussion
This is another function that has to wait on the numeric tower.
-Crosslinks
+Crosslinks
-i
-Basis Combinator
-Append a quoted expression onto the pending expression.
--[Q] . i -------------- - . QDiscussion
-This is a fundamental combinator. It is used in all kinds of places. For example, the x combinator can be defined as
-dup i.
id
Basis Function
The identity function.
-Discussion
+Discussion
Does nothing. It’s kind of a mathematical thing, but it occasionally comes in handy.
ifte
@@ -1303,11 +1076,11 @@ a F a-[if] [then] [else] ifte --------------------------------------- [if] nullary [else] [then] branchDefinition
+Definition
-Crosslinks
+Crosslinks
ii
@@ -1316,7 +1089,7 @@ a F a-... a [Q] ii ------------------ ... Q a QDefinition
+Definition
@@ -1331,7 +1104,7 @@ a F a 1 2 4 4 [++] • i 1 2 4 4 • ++ 1 2 4 5 • -Discussion
+Discussion
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 [+] app2 ---------------------- 1 2 5 6 -1 2 3 4 [+] ii -------------------- @@ -1340,28 +1113,45 @@ a F aCrosslinks
+Crosslinks
+i
+Basis Combinator
+Append a quoted expression onto the pending expression.
++[Q] . i +------------- + . QDiscussion
+This is a fundamental combinator. It is used in all kinds of places. For example, the x combinator can be defined as
+dup i.
infra
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 --------------------------------- c b a Q [z y x ...] swaackDefinition
+Definition
-Discussion
++... [a b c] [F] swons swaack [i] dip swaack +... [[F] a b c] swaack [i] dip swaack + +c b a [F] [...] [i] dip swaack +c b a [F] i [...] swaack +c b a F [...] swaack +d e [...] swaack +... [e d]Discussion
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
-infralets you work on its internal structure.Crosslinks
+Crosslinks
infrst
Combinator
Does infra and then extracts the first item from the resulting list.
-Definition
+Definition
@@ -1370,7 +1160,7 @@ a F aCreate a new Joy function definition in the Joy dictionary. A definition is given as a quote with a name followed by a Joy expression.
Example
-[sqr dup mul] inscribeDiscussion
+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.txtfile. It can be abused, which you should avoid unless you know what you’re doing.
le
@@ -1380,9 +1170,45 @@ a F a ------------- Boolean (a <= b) -Crosslinks
+Crosslinks
+<=
+See le.
+
+<>
+See ne.
+
+<{}
+Function
++... a <{} +---------------- + ... [] aDefinition
++[] swapDiscussion
+Tuck an empty list just under the first item on the stack.
+Crosslinks
+ +
+<<{}
+Function
++... b a <{} +----------------- + ... [] b aDefinition
++[] rollupDiscussion
+Tuck an empty list just under the first two items on the stack.
+Crosslinks
+ +
+<<
+See lshift.
+
+<
+See lt.
+
loop
Basis Combinator
Expect a quoted program
@@ -1393,13 +1219,13 @@ a F a true [Q] . loop -------------------------- . Q [Q] loop -Qand a Boolean value on the stack. If the value is false discard the quoted program, otherwise run a copy ofQandloopagain.Discussion
+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 Gis likeG(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.
-Crosslinks
+Crosslinks
lshift
@@ -1408,7 +1234,7 @@ a F a-a n lshift ---------------- (a×2ⁿ)Crosslinks
+Crosslinks
lt
@@ -1418,7 +1244,7 @@ a F a ------------- Boolean (a < b) -Crosslinks
+Crosslinks
make_generator
@@ -1435,13 +1261,13 @@ a F a-[230 [dup ++] codireco] 5 [x] times pop --------------------------------------------- 230 231 232 233 234Definition
+Definition
-Discussion
+Discussion
See the “Using
-xto Generate Values” notebook.Crosslinks
+Crosslinks
map
@@ -1451,9 +1277,9 @@ a F a-5 [1 2 3] [++ *] map -------------------------- 5 [10 15 20]Discussion
+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
+Crosslinks
max
@@ -1463,7 +1289,7 @@ a F a-[1 2 3 4] max ------------------- 4Crosslinks
+Crosslinks
min
@@ -1473,7 +1299,7 @@ a F a-[1 2 3 4] min ------------------- 1Crosslinks
+Crosslinks
mod
@@ -1482,7 +1308,7 @@ a F a-a b mod ------------- (a%b)Crosslinks
+Crosslinks
modulus
@@ -1494,9 +1320,20 @@ a F a-a b mul ------------- (a×b)Crosslinks
+Crosslinks
+neg
+Function
+Invert the sign of a number.
++a neg +----------- + -aDefinition
++ ++
ne
Basis Function
Not-Equal comparison of the two items on the top of the stack, replacing them with a Boolean value.
@@ -1504,20 +1341,9 @@ a F a ------------- Boolean (a = b) -Crosslinks
+Crosslinks
-neg
-Function
-Invert the sign of a number.
--a neg ------------ - -aDefinition
-- --
not
Function
Like bool but convert the item on the top of the stack to the inverse Boolean value.
@@ -1528,11 +1354,11 @@ a F a false not --------------- true -Definition
+Definition
-Crosslinks
+Crosslinks
nulco
@@ -1541,14 +1367,14 @@ a F a-[F] nulco ------------------- [[F] nullary]Definition
+Definition
-Discussion
-Helper function for || and &&.
-Crosslinks
- +Discussion
+Helper function for || and &&.
+Crosslinks
+
nullary
Combinator
@@ -1556,7 +1382,7 @@ a F a-... [P] nullary --------------------- ... aDefinition
+Definition
@@ -1567,9 +1393,9 @@ a F a ... [...] [P] infra first ... [a ...] first ... a -Discussion
+Discussion
A very useful function that runs any other quoted function and returns it’s first result without disturbing the stack (under the quoted program.)
-Crosslinks
+Crosslinks
of
@@ -1579,17 +1405,17 @@ a F a-2 [a b c d] of -------------------- cDefinition
+Definition
-Crosslinks
+Crosslinks
or
Basis Function
Logical bit-wise OR.
-Crosslinks
+Crosslinks
over
@@ -1598,7 +1424,7 @@ a F a-a b over -------------- a b aDefinition
+Definition
There are many many ways to define this function.
@@ -1616,9 +1442,9 @@ a F aAnd so on…
-Discussion
+Discussion
A fine old word from Forth.
-Crosslinks
+Crosslinks
pam
@@ -1628,29 +1454,64 @@ a F a-5 7 [[+][-][*][/][%]] pam ------------------------------- 5 7 [12 -2 35 0 5]Definition
+Definition
-Discussion
+Discussion
A specialization of map that runs a list of functions in parallel (if the underlying map function is so implemented, of course.)
-Crosslinks
+Crosslinks
+%
+See mod.
+
pick
See getitem.
++
+See add.
+
+++
+See succ.
+
pm
Function
Plus or minus. Replace two numbers with their sum and difference.
-a b pm ----------------- (a+b) (a-b)Definition
+Definition
[+] [-] clop
+popdd
+Function
+pop the third item on the stack.
++a b c popdd +----------------- + b cDefinition
++ ++Crosslinks
+pop popd popop popopd popopdd popopop
+
+popd
+Function
+pop the second item down on the stack.
++a b popd +-------------- + bDefinition
++ ++Crosslinks
+pop popdd popop popopd popopdd popopop
+
pop
Basis Function
Pop the top item from the stack and discard it.
@@ -1659,31 +1520,30 @@ a F aCrosslinks
popd popdd popop popopd popopdd popopop
-popd
+popopdd
Function
-pop the second item down on the stack.
-+a b popd --------------- - ba b c d popopdd +--------------------- + c dDefinition
- +Crosslinks
-pop popdd popop popopd popopdd popopop
+pop popd popdd popop popopd popopop
-popdd
+popopd
Function
-pop the third item on the stack.
-+a b c popdd ------------------ - b cpop the second and third items from the stack.
+a b c popopd +------------------ + cDefinition
- +Crosslinks
-pop popd popop popopd popopdd popopop
+pop popd popdd popop popopdd popopop
popop
Function
@@ -1697,46 +1557,21 @@ a F aCrosslinks
pop popd popdd popopd popopdd popopop
-popopd
-Function
-pop the second and third items from the stack.
--a b c popopd ------------------- - cDefinition
-- --Crosslinks
-pop popd popdd popop popopdd popopop
-
-popopdd
-Function
--a b c d popopdd ---------------------- - c dDefinition
-- --Crosslinks
-pop popd popdd popop popopd popopop
-
popopop
Function
pop three items from the stack.
-a b c popopop -------------------Definition
+Definition
-Crosslinks
+Crosslinks
pop popd popdd popop popopd popopdd
pow
Basis Function
-Take two numbers
+aandbfrom the stack and raiseato thenth power. (bis on the top of the stack.)Take two numbers
aandnfrom the stack and raiseato thenth power. (nis on the top of the stack.)@@ -1748,11 +1583,11 @@ a F aa n pow ------------- (aⁿ)pred
Function
Predecessor. Decrement TOS.
-Definition
+Definition
-1 -
Crosslinks
+Crosslinks
primrec
@@ -1774,15 +1609,15 @@ a F a n [Base] [Recur] primrec ------------------------------------------ n > 0 n (n-1) [Base] [Recur] primrec Recur -Discussion
+Discussion
Simple and useful specialization of the genrec combinator from the original Joy system.
-Crosslinks
+Crosslinks
product
Function
Just as sum sums a list of numbers, this function multiplies them together.
-Definition
+Definition
@@ -1791,19 +1626,31 @@ a F a
Function
+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.
+Function
“Quote D” Wrap the second item on the stack in a list.
a b quoted
----------------
[a] b
--
This comes from the original Joy stuff.
--[0 <=] [1 - dup] anamorphism
If n is less than 1 the resulting list is empty.
5 range_to_zero
---------------------
[0 1 2 3 4 5]
--
Note that the order is reversed compared to range.
- a [b ...] reco
--------------------
[a ...]
--
See mod.
See mod.
[1 2 3 1] 1 remove
------------------------
[2 3 1]
-See the “Remove Function” notebook.
[a ...] rest
------------------
[...]
- [1 2 3] reverse
---------------------
[3 2 1]
-- +
a b c rolldown
--------------------
b c a
--
Function
- a b c rollup
-------------------
- c a b
-- --
See rollup.
See rolldown.
Function
+ a b c rollup
+------------------
+ c a b
++ ++
Function
Round a number to a given precision in decimal digits.
-Another one that won’t make sense until the “numeric tower” is nailed down.
[a b ...] rrest
---------------------
[...]
--
a n rshift
----------------
(a∕2ⁿ)
- [1 2 +] run
-----------------
[3]
-- +
[a b ...] second
----------------------
b
--
The sequence can contain more than two items but not fewer.
-Function
Print redistribution information.
-Mathematically this is a form of id, but it has the side-effect of printing out the GPL notice.
- [x y z] [a b c] shift
---------------------------
[a x y z] [b c]
--
[a b c] [d e f] shunt
---------------------------
[f e d a b c]
--
This is more efficient than concat so prefer it if you don’t need to preserve order.
- [23 [cats] 4] size
------------------------
3
-See floordiv.
+See floordiv.
+See floordiv.
+Function
Given a list return it sorted.
@@ -2047,7 +1903,7 @@ a F aFunction
Example code.
-See the “Square Spiral Example Joy Code” notebook.
[1 2 3 4 5 6 7] 4 split_at
--------------------------------
[5 6 7] [4 3 2 1]
--
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.
[1 2 3 4 5 6 7] 4 split_list
----------------------------------
[1 2 3 4] [5 6 7]
--
Compare with split_at. This function does extra work to ensure that concat would reconstruct the original list.
- n sqr
------------
n²
-@@ -2095,9 +1951,21 @@ a F a
Basis Function Combinator
Return the square root of the number a. Negative numbers return complex roots.
-Another “numeric tower” hatch…
Function
+Grab the stack under the top item and put it onto the stack.
+ ... 1 2 3 stackd
+------------------------
+ ... 1 2 [2 1 ...] 3
++ ++
Function
Put the stack onto the stack.
@@ -2108,23 +1976,11 @@ a F a-
This function forms a pair with [unstack], and together they form the complement to the “destructive” pair enstacken and disenstacken.
-[unstack] enstacken disenstacken
Function
-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.
@@ -2141,9 +1997,9 @@ a F a ... [a b c] [Q] . step ---------------------------------------- ... a . Q [b c] [Q] step -See the Recursion Combinators notebook.
- [...] [F] step_zero
-------------------------
0 [...] [F] step
--
size and sum can both be defined in terms of this specialization of step.
- 1 2 3 stuncons
--------------------
1 2 3 3 [2 1]
-@@ -2180,11 +2036,11 @@ a F a
1 2 3 stununcons
----------------------
1 2 3 3 2 [1]
--
a b sub
-------------
(a-b)
-Function
Successor. Increment TOS.
--1 +
[1 2 3 4 5] sum
---------------------
15
--[+] step_zero
1 2 3 [4 5 6] swaack
--------------------------
6 5 4 [3 2 1]
-This function works as a kind of “context switch”. It’s used in the definition of infra.
-Function
+Swap the second and third items on the stack.
+ a b c swapd
+-----------------
+ b a c
++ ++
Basis Function
Swap the top two items on the stack.
@@ -2241,27 +2110,14 @@ a F aFunction
-Swap the second and third items on the stack.
- a b c swapd
------------------
- b a c
-- --
Function
concat two lists, but swap the lists first.
--
[...] a swons
-------------------
[a ...]
-@@ -2278,14 +2134,14 @@ a F a
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.
- [a b c d] 2 take
----------------------
[b a]
-- +
... z y x [P] ternary
-------------------------
... a
--
Runs any other quoted function and returns its first result while consuming exactly three items from the stack.
- [a b c ...] third
-----------------------
c
--
-[-- dip] cons [swap] infra [0 >] swap while pop :
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
@@ -2367,11 +2223,11 @@ a F a
a b tuck
--------------
b a b
--
... x [P] unary
---------------------
... a
--
Runs any other quoted function and returns its first result while consuming exactly one item from the stack.
- [a ...] uncons
--------------------
a [...]
-This is the inverse of cons.
- a unit
------------
[a]
-@@ -2421,11 +2277,11 @@ a F a[] cons
1 2 [3 4] 5 unquoted
--------------------------
1 2 3 4 5
--
[a ...] unswons
---------------------
[...] a
-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
+Basis Function
True if the form on TOS is void otherwise False.
diff --git a/docs/html/css/func_ref.css b/docs/html/css/func_ref.css new file mode 100644 index 0000000..793ed51 --- /dev/null +++ b/docs/html/css/func_ref.css @@ -0,0 +1,33 @@ + +body { + background: #fff; + color: black; + font-family: 'EB Garamond 12'; +} + +footer { + margin-top: 2em; + font-family: 'EB Garamond SC 08'; + font-size: x-small; + text-align: center; +} + +code { + background: #eee; +} + +pre { + background: #eee; + margin-left: 2em; + margin-right: 2em; + margin-bottom: 1em; + font-family: 'Inconsolata'; + padding: 0.5em; +} + +blockquote { + font-family: monospace, 'Inconsolata'; + background: #eee; + border-left: 0.2em solid black; + padding: 0.5em; +} diff --git a/docs/reference/FuncRef.html b/docs/reference/FuncRef.html index 09ce269..4918cc4 100644 --- a/docs/reference/FuncRef.html +++ b/docs/reference/FuncRef.html @@ -13,6 +13,8 @@ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} + +Version -10.0.0
Each function, combinator, or definition should be documented here.