Thun/docs/reference/Functor-Reference.md

60 KiB

Functor Reference

Version -10.0.0

Each function, combinator, or definition should be documented here.


&

Basis Function Combinator

Same as a & b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


&&

Basis Function Combinator

nulco [nullary [false]] dip branch

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


*

Basis Function Combinator

Same as a * b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


Basis Function Combinator

The identity function.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


^

Basis Function Combinator

Same as a ^ b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


=

Basis Function Combinator

Same as a == b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


!=

Basis Function Combinator

Same as a != b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


!-^^^^

Basis Function Combinator

0 >=

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.

Crosslinks


>

Basis Function Combinator

Same as a > b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


>=

Basis Function Combinator

Same as a >= b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


>>

Basis Function Combinator

Same as a >> b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.

Functor Reference

Version -10.0.0

Each function, combinator, or definition should be documented here.


-^^^

Basis Function Combinator

Same as a - b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.

Crosslinks


--^^^^

Basis Function Combinator

Decrement TOS.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.

Crosslinks


<

Basis Function Combinator

Same as a < b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


<=

Basis Function Combinator

Same as a <= b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


<>

Basis Function Combinator

Same as a != b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


<

Basis Function Combinator

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


<<

Basis Function Combinator

Same as a << b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


<<

Basis Function Combinator

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


%

Basis Function Combinator

Same as a % b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


+

Basis Function Combinator

Same as a + b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


++

Basis Function Combinator

Increment TOS.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


?

Basis Function Combinator

dup bool

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


/

Basis Function Combinator

Same as a // b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


//

Basis Function Combinator

Same as a // b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


/floor

Basis Function Combinator

Same as a // b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


||

Basis Function Combinator

nulco [nullary] dip [true] branch

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


abs

Basis Function Combinator

Return the absolute value of the argument.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


add

Basis Function Combinator

Same as a + b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


anamorphism

Basis Function Combinator

pop \[

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


and

Basis Function Combinator

Same as a & b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


app1

"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

Definition

nullary popd

Discussion

Just a specialization of nullary really. Its parallelizable cousins are more useful.


app2

Basis Function Combinator

Like app1 with two items.

... y x [Q] . app2 ----------------------------------- ... [y ...] [Q] . infra first [x ...] [Q] infra first

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


app3

Basis Function Combinator

Like app1 with three items.

... z y x [Q] . app3 ----------------------------------- ... [z ...] [Q] . infra first [y ...] [Q] infra first [x ...] [Q] infra first

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


appN

Basis Function Combinator

grabN

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


at

Basis Function Combinator

getitem == drop first

Expects an integer and a quote on the stack and returns the item at the nth position in the quote counting from 0. :

[a b c d] 0 getitem
-------------------------
 a

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


average

Basis Function Combinator

sum

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


b

(Combinator)

Run two quoted programs

   [P] [Q] b
---------------
      P Q

Definition

[i] dip i

Derivation

[P] [Q] b
[P] [Q] [i] dip i
[P] i [Q] i
 P    [Q] i
 P     Q

Discussion

This combinator comes in handy.

dupdip ii


binary

(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

Definition

unary popd

Discussion

Runs any other quoted function and returns its first result while consuming exactly two items from the stack.

nullary ternary unary


bool

Basis Function Combinator

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


branch

Basis Function Combinator

Use a Boolean value to select one of two quoted programs to run.

branch == roll< choice i

False [F] [T] branch
--------------------------
   F

True [F] [T] branch
-------------------------
      T

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


ccccons

Basis Function Combinator

ccons ccons

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


ccons

(Function)

Given two items and a list, append the items to the list to make a new list.

   B A [...] ccons
---------------------
      [B A ...]

Definition

cons cons

Discussion

Does cons twice.

cons


choice

Basis Function Combinator

Use a Boolean value to select one of two items. :

A B false choice
----------------------
A


A B true choice
---------------------
  B

Currently Python semantics are used to evaluate the "truthiness" of the Boolean value (so empty string, zero, etc. are counted as false, etc.)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


clear

Basis Function Combinator

Clear everything from the stack.

clear == stack [pop stack] loop

   ... clear
---------------

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


cleave

Basis Function Combinator

fork popdd

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


clop

Basis Function Combinator

cleave popdd

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


cmp

Basis Function Combinator

cmp takes two values and three quoted programs on the stack and runs 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

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


codi

Basis Function Combinator

cons dip

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


codireco

Basis Function Combinator

codi reco

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


concat

Basis Function Combinator

Concatinate the two lists on the top of the stack. :

[a b c] [d e f] concat
----------------------------
    [a b c d e f]

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


cond

Basis Function 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 clause 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.

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

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


cons

(Basis Function)

Given an item and a list, append the item to the list to make a new list.

   A [...] cons
------------------
     [A ...]

Source

func(cons, [list(A), B|S], [list([B|A])|S]).

Discussion

Cons is a venerable old function from Lisp. It doesn't inspect the item but it will not cons onto a non-list. It's inverse operation is called uncons.

ccons uncons


dinfrirst

Basis Function Combinator

dip infrst

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


dip

Basis Function 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

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


dipd

Basis Function Combinator

Like dip but expects two items. :

... y x [Q] dip
---------------------
  ... Q y x

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


dipdd

Basis Function Combinator

Like dip but expects three items. :

... z y x [Q] dip
-----------------------
  ... Q z y x

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


disenstacken

Basis Function Combinator

The disenstacken operator expects a list on top of the stack and makes that the stack discarding the rest of the stack.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


div

Basis Function Combinator

Same as a // b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


divmod

Basis Function Combinator

divmod(x, y) -> (quotient, remainder)

Return the tuple (x//y, x%y). Invariant: q * y + r == x.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


down_to_zero

Basis Function Combinator

0 \>

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


drop

Basis Function Combinator

drop == [rest] times

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]

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


dup

Basis Function Combinator

(a1 -- a1 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


dupd

Basis Function Combinator

(a2 a1 -- a2 a2 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


dupdd

Basis Function Combinator

(a3 a2 a1 -- a3 a3 a2 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


dupdip

Basis Function Combinator

[F] dupdip == dup [F] dip

... a [F] dupdip
... a dup [F] dip
... a a   [F] dip
... a F a

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


dupdipd

Basis Function Combinator

dup dipd

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


enstacken

Basis Function Combinator

stack [clear] dip

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


eq

Basis Function Combinator

Same as a == b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


first

Basis Function Combinator

([a1 ...1] -- a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


first_two

Basis Function Combinator

([a1 a2 ...1] -- a1 a2)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


flatten

Basis Function Combinator

<{} [concat] step

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


floor

Basis Function Combinator

Return the floor of x as an Integral.

This is the largest integer <= x.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


floordiv

Basis Function Combinator

Same as a // b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


fork

Basis Function Combinator

i

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


fourth

Basis Function Combinator

([a1 a2 a3 a4 ...1] -- a4)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


gcd

Basis Function Combinator

true [tuck mod dup 0 >] loop pop

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


gcd2

Basis Function Combinator

Compiled GCD function.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


ge

Basis Function Combinator

Same as a >= b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


genrec

Basis Function Combinator

General Recursion Combinator. :

[if] [then] [rec1] [rec2] genrec
---------------------------------------------------------------------
[if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte

From "Recursion Theory and Joy" (j05cmp.html) by Manfred von Thun: "The genrec combinator takes four program parameters in addition to whatever data parameters it needs. Fourth from the top is an if-part, followed by a then-part. If the if-part yields true, then the then-part is executed and the combinator terminates. The other two parameters are the rec1-part and the rec2-part. If the if-part yields false, the rec1-part is executed. Following that the four program parameters and the combinator are again pushed onto the stack bundled up in a quoted form. Then the rec2-part is executed, where it will find the bundled form. Typically it will then execute the bundled form, either with i or with app2, or some other combinator."

The way to design one of these is to fix your base case [then] and the test [if], and then treat rec1 and rec2 as an else-part "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

Primitive recursive functions are those where R2 == i. :

P == [I] [T] [R] tailrec
  == [I] [T] [R [P] i] ifte
  == [I] [T] [R P] ifte

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


getitem

Basis Function Combinator

getitem == drop first

Expects an integer and a quote on the stack and returns the item at the nth position in the quote counting from 0. :

[a b c d] 0 getitem
-------------------------
 a

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


grabN

Basis Function Combinator

<{} [cons] times

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


grba

Basis Function Combinator

stack popd

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


gt

Basis Function Combinator

Same as a > b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


help

Basis Function Combinator

Accepts a quoted symbol on the top of the stack and prints its docs.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


hypot

Basis Function Combinator

sqr

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


i

(Basis Combinator)

Append a quoted expression onto the pending expression.

   [Q] i
-----------
    Q

Source

combo(i, [list(P)|S], S, Ei, Eo) :- append(P, Ei, Eo).

Discussion

This is probably the fundamental combinator. You wind up using it in all kinds of places (for example, the x combinator can be defined as dup i.)


id

Basis Function Combinator

The identity function.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


ifte

Basis Function Combinator

If-Then-Else Combinator :

... [if] [then] [else] ifte
---------------------------------------------------
... [[else] [then]] [...] [if] infra select i




... [if] [then] [else] ifte
-------------------------------------------------------
... [else] [then] [...] [if] infra first choice i

Has the effect of grabbing a copy of the stack on which to run the if-part using infra.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


ii

Basis Function Combinator

... a [Q] ii
------------------
 ... Q a Q

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


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.)

   ... [a b c] [Q] infra
---------------------------
    c b a Q [...] swaack

Definition

swons swaack [i] dip swaack

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 infra lets you work on its internal structure.

swaack


infrst

Basis Function Combinator

infra first

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


inscribe

Basis Function Combinator

Create a new Joy function definition in the Joy dictionary. A definition is given as a quote with a name followed by a Joy expression. for example:

sqr dup mul

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


le

Basis Function Combinator

Same as a <= b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


loop

Basis Function Combinator

Basic loop combinator. :

... True [Q] loop
-----------------------
   ... Q [Q] loop

... False [Q] loop
------------------------
   ...

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


lshift

Basis Function Combinator

Same as a << b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


lt

Basis Function Combinator

Same as a < b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


make_generator

Basis Function Combinator

codireco

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


map

Basis Function Combinator

Run the quoted program on TOS on the items in the list under it, push a new list with the results in place of the program and original list.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


max

Basis Function Combinator

Given a list find the maximum.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


min

Basis Function Combinator

Given a list find the minimum.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


mod

Basis Function Combinator

Same as a % b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


modulus

Basis Function Combinator

Same as a % b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


mul

Basis Function Combinator

Same as a * b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


ne

Basis Function Combinator

Same as a != b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


neg

Basis Function Combinator

Same as -a.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


not

Basis Function Combinator

Same as not a.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


!-

"not negative"

(Function, Boolean Predicate)

Integer on top of stack is replaced by Boolean value indicating whether it is non-negative.

    N !-
-----------  N < 0
   false

   N !-
----------  N >= 0
   true

Definition

0 >=

nulco

Basis Function Combinator

nullary

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


nullary

(Combinator)

Run a quoted program without using any stack values and leave the first item of the result on the stack.

   ... [P] nullary
---------------------
        ... A

Definition

[stack] dip infra first

Derivation

... [P] nullary
... [P] [stack] dip infra first
... stack [P] infra first
... [...] [P] infra first
... [A ...] first
...  A

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.)

unary binary ternary


of

Basis Function Combinator

swap at

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


or

Basis Function Combinator

Same as a | b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


over

Basis Function Combinator

(a2 a1 -- a2 a1 a2)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


pam

Basis Function Combinator

i

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


pick

Basis Function Combinator

getitem == drop first

Expects an integer and a quote on the stack and returns the item at the nth position in the quote counting from 0. :

[a b c d] 0 getitem
-------------------------
 a

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


pm

Basis Function Combinator

Plus or minus :

a b pm
-------------
a+b a-b

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


pop

Basis Function Combinator

(a1 --)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


popd

Basis Function Combinator

(a2 a1 -- a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


popdd

Basis Function Combinator

(a3 a2 a1 -- a2 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


popop

Basis Function Combinator

(a2 a1 --)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


popopd

Basis Function Combinator

(a3 a2 a1 -- a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


popopdd

Basis Function Combinator

(a4 a3 a2 a1 -- a2 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


popopop

Basis Function Combinator

pop popop

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


pow

Basis Function Combinator

Same as a ** b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


pred

Basis Function Combinator

Decrement TOS.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


primrec

Basis Function Combinator

From the "Overview of the language JOY":

> The primrec combinator expects two quoted programs in addition to a data parameter. For an integer data parameter it works like this: If the data parameter is zero, then the first quotation has to produce the value to be returned. If the data parameter is positive then the second has to combine the data parameter with the result of applying the function to its predecessor.:

5  [1]  [*]  primrec

> Then primrec tests whether the top element on the stack (initially the 5) is equal to zero. If it is, it pops it off and executes one of the quotations, the [1] which leaves 1 on the stack as the result. Otherwise it pushes a decremented copy of the top element and recurses. On the way back from the recursion it uses the other quotation, [*], to multiply what is now a factorial on top of the stack by the second element on the stack.:

n [Base] [Recur] primrec

   0 [Base] [Recur] primrec
------------------------------
      Base

     n [Base] [Recur] primrec
------------------------------------------ n > 0
   n (n-1) [Base] [Recur] primrec Recur

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


product

Basis Function Combinator

1 swap [*] step

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


quoted

Basis Function Combinator

unit

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


range

Basis Function Combinator

0 \<=

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


range_to_zero

Basis Function Combinator

unit [down_to_zero] infra

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


reco

Basis Function Combinator

rest cons

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


rem

Basis Function Combinator

Same as a % b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


remainder

Basis Function Combinator

Same as a % b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


remove

Basis Function Combinator

Expects an item on the stack and a quote under it and removes that item from the the quote. The item is only removed once. If the list is empty or the item isn't in the list then the list is unchanged. :

[1 2 3 1] 1 remove
------------------------
  [2 3 1]

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


rest

Basis Function Combinator

([a1 ...0] -- [...0])

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


reverse

Basis Function Combinator

Reverse the list on the top of the stack. :

reverse == [] swap shunt

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


rolldown

Basis Function Combinator

(a1 a2 a3 -- a2 a3 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


rollup

Basis Function Combinator

(a1 a2 a3 -- a3 a1 a2)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


roll>

Basis Function Combinator

(a1 a2 a3 -- a3 a1 a2)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


roll<

Basis Function Combinator

(a1 a2 a3 -- a2 a3 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion

Lorem ipsum.


round

Basis Function Combinator

Round a number to a given precision in decimal digits.

The return value is an integer if ndigits is omitted or None. Otherwise the return value has the same type as the number. ndigits may be negative.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


rrest

Basis Function Combinator

([a1 a2 ...1] -- [...1])

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


rshift

Basis Function Combinator

Same as a >> b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


run

Basis Function Combinator

<{} infra

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


second

Basis Function Combinator

([a1 a2 ...1] -- a2)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


select

Basis Function Combinator

Use a Boolean value to select one of two items from a sequence. :

[A B] false select
------------------------
 A


[A B] true select
-----------------------
   B

The sequence can contain more than two items but not fewer. Currently Python semantics are used to evaluate the "truthiness" of the Boolean value (so empty string, zero, etc. are counted as false, etc.)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


sharing

Basis Function Combinator

Print redistribution information.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


shift

Basis Function Combinator

uncons [swons] dip

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


shunt

Basis Function Combinator

Like concat but reverses the top list into the second. :

shunt == [swons] step == reverse swap concat

   [a b c] [d e f] shunt
---------------------------
       [f e d a b c] 

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


size

Basis Function Combinator

pop ++

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


sort

Basis Function Combinator

Given a list return it sorted.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


spiral_next

Basis Function Combinator

\[\[abs
\[++

ifte

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


split_at

Basis Function Combinator

drop

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


split_list

Basis Function Combinator

take reverse

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


sqr

Basis Function Combinator

dup *

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


sqrt

Basis Function Combinator

Return the square root of the number a. Negative numbers return complex roots.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


stack

Basis Function Combinator

(... -- ... [...])

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


stackd

Basis Function Combinator

stack

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


step

Basis Function Combinator

Run a quoted program on each item in a sequence. :

... [] [Q] . step
-----------------------
   ... .


... [a] [Q] . step
------------------------
  ... a . Q


... [a b c] [Q] . step
----------------------------------------
      ... a . Q [b c] [Q] step

The step combinator executes the quotation on each member of the list on top of the stack.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


step_zero

Basis Function Combinator

0 roll> step

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


stuncons

Basis Function Combinator

(... a1 -- ... a1 a1 [...])

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


stununcons

Basis Function Combinator

(... a2 a1 -- ... a2 a1 a1 a2 [...])

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


sub

Basis Function Combinator

Same as a - b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


succ

Basis Function Combinator

Increment TOS.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


sum

Basis Function Combinator

Given a quoted sequence of numbers return the sum. :

sum == 0 swap [+] step

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


swaack

Basis Function Combinator

([...1] -- [...0])

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


swap

Basis Function Combinator

(a1 a2 -- a2 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


swapd

Basis Function Combinator

swap

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


swoncat

Basis Function Combinator

swap concat

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


swons

Basis Function Combinator

([...1] a1 -- [a1 ...1])

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


tailrec

Basis Function Combinator

i

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


take

Basis Function Combinator

Expects an integer and a quote on the stack and returns the quote with just the top n items in reverse order (because that's easier and you can use reverse if needed.) :

[a b c d] 2 take
----------------------
    [b a]

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


ternary

(Combinator)

Run a quoted program using exactly three stack values and leave the first item of the result on the stack.

   ... z y x [P] unary
-------------------------
         ... A

Definition

binary popd

Discussion

Runs any other quoted function and returns its first result while consuming exactly three items from the stack.

binary nullary unary


third

Basis Function Combinator

([a1 a2 a3 ...1] -- a3)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


times

Basis Function Combinator

times == [-- dip] cons [swap] infra [0 >] swap while pop :

... n [Q] . times
---------------------  w/ n <= 0
  ... .


... 1 [Q] . times
-----------------------
  ... . Q


... n [Q] . times
-------------------------------------  w/ n > 1
  ... . Q (n - 1) [Q] times

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


truthy

Basis Function Combinator

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


tuck

Basis Function Combinator

(a2 a1 -- a1 a2 a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


unary

(Combinator)

Run a quoted program using exactly one stack value and leave the first item of the result on the stack.

   ... x [P] unary
---------------------
       ... A

Definition

nullary popd

Discussion

Runs any other quoted function and returns its first result while consuming exactly one item from the stack.

binary nullary ternary


uncons

(Basis 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.

   [A ...] uncons
--------------------
      A [...]

Source

func(uncons, Si, So) :- func(cons, So, Si).

Discussion

This is the inverse of cons.

cons


unique

Basis Function Combinator

Given a list remove duplicate items.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


unit

Basis Function Combinator

(a1 -- [a1 ])

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


unquoted

Basis Function Combinator

i

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


unswons

Basis Function Combinator

([a1 ...1] -- [...1] a1)

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


void

Basis Function Combinator

True if the form on TOS is void otherwise False.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


warranty

Basis Function Combinator

Print warranty information.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


while

Basis Function Combinator

swap nulco dupdipd concat loop

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


words

Basis Function Combinator

Print all the words in alphabetical order.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


x

(Combinator)

   [F] x
-----------
   [F] F

Definition

dup i

Discussion

The x combinator ...


xor

Basis Function Combinator

Same as a ^ b.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion


zip

Basis Function Combinator

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.

Gentzen diagram.

Definition

if not basis.

Derivation

if not basis.

Source

if basis

Discussion