Functional()
Paradigm(s) | functional |
---|---|
Designed by | User:Hakerh400 |
Appeared in | 2018 |
Computational class | Turing complete |
Major implementations | Functional() interpreter |
File extension(s) | .txt |
Functional() is an esoteric Turing complete programming language.
Syntax
Source code is represented in the ASCII encoding and consists of characters (
, )
, ,
, whitespace characters and identifiers. Example:
abc(d(e, e1), f, g()), h(&&(^), $(@, ~))(abc)
Everything that is not (
, )
, ,
or whitespace is considered as an identifier. Thus, the identifiers in the above example are abc
, d
, e
, e1
, f
, g
, h
, &&
, ^
, $
, @
, ~
.
Each program represents a List of zero or more CallChains. A CallChain is an identifier followed by zero or more Lists surrounded by a pair of parentheses. Elements of a List are separated by ,
.
The above example has two main CallChains: abc(d(e, e1), f, g())
and h(&&(^), $(@, ~))(abc)
. The first CallChain consists of identifier abc
and List (d(e, e1), f, g())
, while the second CallChain consists of identifier h
and two Lists: (&&(^), $(@, ~))
and (abc)
.
Evaluation
Each identifier has a function associated with it. When program starts, the main List starts to evaluate.
List evaluates in the following way:
- If the List is empty, return the function associated with the 0th global identifier
- Otherwise evaluate all List's CallChains
CallChain evaluates in the following way:
- If the CallChain has no Lists, return the value of the CallChain's identifier
- Otherwise do the following
- Evaluate all CallChain's Lists
- Call the function associated with the first List as arguments
- Remove the first List
- Replace the identifier with the result of the call
- If there are no more List, return the value of the identifier
- Otherwise go to 2.2.
There are some exceptions to these rules.
Functions
Functional() has 6 native functions. Native functions have no reserved identifiers, but their values are assigned to the first 6 identifiers (reading from left to right) that appear in the source code. If the source code has less identifiers that the number of native functions, some native functions will not be assigned to any identifier.
The native functions are:
Zero
Takes two arguments, returns the second one.
One
Takes two arguments, returns the first one.
Equality
Takes two arguments, returns 1 if they are the same, otherwise returns 0.
Assign
Takes two arguments, if the first one is not an identifier returns 0, otherwise assigns the second argument to the identifier from the first argument.
Variable
Takes two arguments, if the first one is not an identifier returns 0, otherwise creates a new variable in the most inner scope with name equals to the identifier from the first argument and assigns the second argument to that variable.
New function
Takes zero or more arguments, if any of the arguments is not an identifier returns 0, otherwise returns a FunctionTemplate.
FunctionTemplate is a function which has an internal list of formal arguments. When called, it doesn't evaluate it's arguments, but stores the argument list as its body and returns a new UserlandFunction.
UserlandFunction takes zero or more arguments and evaluates them. Then each evaluated argument is assigned to the corresponding internal formal argument and the function body is evaluated in the new scope based on the formal and actual arguments.
IO interface
Functional() provides a way of adding native functions before running a program. The standard implementation provides 3 new functions for IO interface:
Read
Takes no arguments, returns the next bit (0 or 1) from the input stream
Write
Takes one argument, outputs the bit to the output stream and returns 0.
Eof
Takes no arguments, returns 1 if there are no more bits in the input stream, otherwise returns 0.
These functions are assigned to the 7th, 8th and 9th identifier from the source code.
The function Write considers the 0th global identifier as bit 0 and anything other as bit 1. Both Read and Write process bits from input/output starting at the lowest bit of the first byte to the highest bit of the first byte, then the second byte, end so on. Calling Read after all input is read returns 0.
If the program is terminated, but the output has no enough bits to form a byte, the output will be padded with 0-bits in order to complete the byte.
Examples
We assume the standard IO interface implementation is used. The first 9 identifiers that appear in the source code will be native functions. Accessing undefined identifier returns 0 (actually the 0th global identifier, which may be overriden though).
In these examples we will use identifiers 0
, 1
, ==
, =
, var
, []
, read
, write
, eof
respectively. Note that there is nothing special about ==
, =
, []
, they are valid identifiers.
Printing characters
This code prints ASCII letter "A".
0, 1, ==, =, var, [], read, write, eof, write(1), write(0), write(0), write(0), write(0), write(0), write(1), write(0)
The ASCII code of letter "A" is 65, which is 1000001 in binary. Because the Read and Write functions process bits from lowest to highest, we need to reverse the bits. The last write(0)
may be omitted because of padding incomplete bytes with 0-bits.
Note: In the following examples the header (first 9 identifiers) are omitted for simplicity, but they are required if you want to run the actual code.
Cat
var(not, [](a)(==(a, 0))), var(bool, [](a)(not(not(a)))), var(while, [](cond, func)( var(temp, bool(cond()))(while)(cond, func, temp(func)()) )), while([]()(not(eof())), []()( write(read()) ))
There are several things demonstrated in this example.
Code [](a)(==(a, 0))
creates a UserlandFunction which takes argument a
and returns the result of comparison a
with 0
. In other words, it returns 1
if a
is 0
, and 0
otherwise.
Code var(not, [](a)(==(a, 0)))
assigns the newly created UserlandFunction to the global identifier not
.
The second line does a similar thing: creates a function which takes argument a
and returns not(not(a))
(converts it to boolean).
Now, the interesting part: while loop. The while loop is just a function which takes two arguments: cond
and func
. While the result of calling cond
returns a truthy value, call func
. It is achieved by recursively calling while
function. We wont explain here in details how and why it works.
It is possible to spin in a while loop forever, without causing a stack overflow. That is done by replacing caller's stack frame with the stack frame of the callee's last CallChain.
Finally, we call our while
function with two UserlandFunctions. The first one returns 1
if eof
returns 0
. The second one reads a bit from the input and writes the bit to the output. In other words: while eof()
is false, read a bit and output it.
Hello, World!
0,1,2,3,4,5,6,7,4(2,5 0(7 0,2))0 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 1 1 1 0 1 0 1 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 1 0 0 0 1 1 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0 1 0 0
Closures
In functional() it is possible to create a closure. A closure is created either by returning a UserlandFunction (defined in the local scope), or passing it as an argument.
var(func, [](a)( []()(a) )), var(closure, func(1)), write(closure()), write(0), write(0), write(0), write(1), write(1)
Function func
takes argument a
and returns a function that takes no arguments and returns a
.
In this example, we are passing 1
as the argument to func
, and then obtaining it again by calling closure()
. Finally, we print the number as ASCII character "1". If you replace func(1)
with func(0)
it will print character "0".
Closures open a lot of possibilities: implementing arrays, matrices, linked lists, multidimensional tensors, etc.
Classes
var(.get, []()()), var(.set, []()()), var(Class, [](a)( var(get, []()(a)), var(set, [](b)(=(a, b))), [](method)( ==(method, .get)(get, ==(method, .set)(set )) ) )), var(obj, Class(0)), write(obj .get()), write(0), write(0), write(0), write(1), write(1), write(0), write(0), obj .set(1), write(obj .get()), write(0), write(0), write(0), write(1), write(1)
Here we have class Class
which has a constructor and two methods. The constructor takes one argument and stores it as a private member a
.
The first method is get
. It takes no arguments and returns the value of a
. Method set
takes an argument (here b
) and assigns the value of b
to a
.
We used two tricks here. The first one is the fact that every UserlandFunction which is created by a separate call to the 6th native function is different, so we can use it like an enum.
The second trick is syntactical: if two identifiers appear one after another (here .get
and .set
appear after obj
) they are interpreted like a CallChain. Note that .get
and .set
are just identifiers, so if you remove the space from obj .get()
it wont work as expected. For example, a .b .c
is equivalent to a(.b)(.c)
, but not a.b.c
.
The above code prints "01".
Advanced examples
In order to create more useful programs, we need to define some standard functions and use them in future programs. Here we are providing a header containing useful functions and constructors. All examples in this section must include this header in order to work properly.
The header
0, 1, ==, =, var, [], read, write, eof, //////////////////////////////////////////////////////////////////////////////////////////////////, var(.head, []()()), var(.tail, []()()), var(.push, []()()), var(.pop, []()()), var(.unshift, []()()), var(.shift, []()()), var(.append, []()()), var(.clone, []()()), var(.forEach, []()()), var(.write, []()()), //////////////////////////////////////////////////////////////////////////////////////////////////, var(not, [](a)(==(a, 0))), var(bool, [](a)(not(not(a)))), var(&&, [](a, b)(a(b))), var(||, [](a, b)(a(1, b))), var(^^, [](a, b)(a(not(b), b))), //////////////////////////////////////////////////////////////////////////////////////////////////, var(while, [](cond, func)( var(temp, bool(cond()))(while)(cond, func, temp(func)()) )), //////////////////////////////////////////////////////////////////////////////////////////////////, var(Pair, [](a, b)( [](mode, index, val)( =(index, not(index)), not(mode)([]()( index(a, b) ), []()( index([]()( =(a, val) ), []()( =(b, val) ))() ))() ) )), //////////////////////////////////////////////////////////////////////////////////////////////////, var(Byte, [](a, b, c, d, e, f, g, h)( var(pair, Pair(Pair(Pair(a, b), Pair(c, d)), Pair(Pair(e, f), Pair(g, h)))), [](mode, i0, i1, i2, val)( pair(0, i2)(0, i1)(mode, i0, val) ) )), var(clone, [](byte)( Byte( byte(0, 0, 0, 0), byte(0, 1, 0, 0), byte(0, 0, 1, 0), byte(0, 1, 1, 0), byte(0, 0, 0, 1), byte(0, 1, 0, 1), byte(0, 0, 1, 1), byte(0, 1, 1, 1) ) )), var(forEach, [](byte, func)( func(byte(0, 0, 0, 0), 0, 0, 0), func(byte(0, 1, 0, 0), 1, 0, 0), func(byte(0, 0, 1, 0), 0, 1, 0), func(byte(0, 1, 1, 0), 1, 1, 0), func(byte(0, 0, 0, 1), 0, 0, 1), func(byte(0, 1, 0, 1), 1, 0, 1), func(byte(0, 0, 1, 1), 0, 1, 1), func(byte(0, 1, 1, 1), 1, 1, 1), byte )), var(map, [](byte, func)( =(byte, clone(byte)), forEach(byte, [](bit, i0, i1, i2)( byte(1, i0, i1, i2, func(bit, i0, i1, i2)) )) )), var(cmp, [](b1, b2)( var(eq), var(gt), var(lt), forEach(b1, [](bit1, i0, i1, i2)( var(bit2, b2(0, i0, i1, i2)), var(eq1, ==(bit1, bit2)), =(gt, ||(&&(gt, eq1), &&(bit1, not(bit2)))), =(lt, ||(&&(lt, eq1), &&(not(bit1), bit2))), =(eq, &&(eq, eq1)) )), Pair(gt, lt) )), var(eq, [](b1, b2)( var(temp, cmp(b1, b2)), not(||(temp(0, 0), temp(0, 1))) )), var(neq, [](b1, b2)( not(eq(b1, b2)) )), var(gt, [](b1, b2)( cmp(b1, b2)(0, 0) )), var(lt, [](b1, b2)( cmp(b1, b2)(0, 1) )), var(gte, [](b1, b2)( not(lt(b1, b2)) )), var(lte, [](b1, b2)( not(gt(b1, b2)) )), var(&, [](b1, b2)( map(a, [](bit, i0, i1, i2)(&&(bit, b2(0, i0, i1, i2)))) )), var(|, [](b1, b2)( map(a, [](bit, i0, i1, i2)(||(bit, b2(0, i0, i1, i2)))) )), var(^, [](b1, b2)( map(a, [](bit, i0, i1, i2)(^^(bit, b2(0, i0, i1, i2)))) )), var(+c, [](b1, b2)( var(carry, 0), Pair(map(b1, [](bit1, i0, i1, i2)( var(bit2, b2(0, i0, i1, i2)), var(temp, ^^(carry, ^^(bit1, bit2))), =(carry, ||(&&(bit1, bit2), ||(&&(bit1, carry), &&(bit2, carry)))), temp )), carry) )), var(+, [](b1, b2)( +c(b1, b2)(0, 0) )), var(neg, [](byte)( +(map(byte, [](bit)(not(bit))), 1n) )), var(-, [](b1, b2)( +(b1, neg(b2)) )), var(*, [](b1, b2)( var(b3, Byte()), while([]()(not(eq(b2, Byte()))), []()( =(b3, +(b3, b1)), =(b2, -(b2, 1n)) )), b3 )), var(/, [](b1, b2)( var(b3, clone(b2)), var(b4, 0n), var(carry, 0), while([]()(not(||(gt(b3, b1), carry))), []()( =(b4, +(b4, 1n)), var(sum, +c(b3, b2)), =(b3, sum(0, 0)), =(carry, sum(0, 1)) )), b4 )), var(%, [](b1, b2)( -(b1, *(/(b1, b2), b2)) )), var(Iterator, [](byte)( var(1n, Byte(1)), not(byte)([]()( =(byte, Byte()) ))(), []()( var(prev, byte), =(byte, +(byte, 1n)), prev ) )), []()( var(next, Iterator()), =(0n, next()), =(1n, next()), =(2n, next()), =(3n, next()), =(4n, next()), =(5n, next()), =(6n, next()), =(7n, next()), =(8n, next()), =(9n, next()), =(10n, next()), =(11n, next()), =(12n, next()), =(13n, next()), =(14n, next()), =(15n, next()), =(16n, next()), =(17n, next()), =(18n, next()), =(19n, next()), =(20n, next()), =(21n, next()), =(22n, next()), =(23n, next()), =(24n, next()), =(25n, next()), =(26n, next()), =(27n, next()), =(28n, next()), =(29n, next()), =(30n, next()), =(31n, next()), =(32n, next()), =(33n, next()), =(34n, next()), =(35n, next()), =(36n, next()), =(37n, next()), =(38n, next()), =(39n, next()), =(40n, next()), =(41n, next()), =(42n, next()), =(43n, next()), =(44n, next()), =(45n, next()), =(46n, next()), =(47n, next()), =(48n, next()), =(49n, next()), =(50n, next()), =(51n, next()), =(52n, next()), =(53n, next()), =(54n, next()), =(55n, next()), =(56n, next()), =(57n, next()), =(58n, next()), =(59n, next()), =(60n, next()), =(61n, next()), =(62n, next()), =(63n, next()), =(64n, next()), =(65n, next()), =(66n, next()), =(67n, next()), =(68n, next()), =(69n, next()), =(70n, next()), =(71n, next()), =(72n, next()), =(73n, next()), =(74n, next()), =(75n, next()), =(76n, next()), =(77n, next()), =(78n, next()), =(79n, next()), =(80n, next()), =(81n, next()), =(82n, next()), =(83n, next()), =(84n, next()), =(85n, next()), =(86n, next()), =(87n, next()), =(88n, next()), =(89n, next()), =(90n, next()), =(91n, next()), =(92n, next()), =(93n, next()), =(94n, next()), =(95n, next()), =(96n, next()), =(97n, next()), =(98n, next()), =(99n, next()), =(100n, next()), =(101n, next()), =(102n, next()), =(103n, next()), =(104n, next()), =(105n, next()), =(106n, next()), =(107n, next()), =(108n, next()), =(109n, next()), =(110n, next()), =(111n, next()), =(112n, next()), =(113n, next()), =(114n, next()), =(115n, next()), =(116n, next()), =(117n, next()), =(118n, next()), =(119n, next()), =(120n, next()), =(121n, next()), =(122n, next()), =(123n, next()), =(124n, next()), =(125n, next()), =(126n, next()), =(127n, next()), =(128n, next()), =(129n, next()), =(130n, next()), =(131n, next()), =(132n, next()), =(133n, next()), =(134n, next()), =(135n, next()), =(136n, next()), =(137n, next()), =(138n, next()), =(139n, next()), =(140n, next()), =(141n, next()), =(142n, next()), =(143n, next()), =(144n, next()), =(145n, next()), =(146n, next()), =(147n, next()), =(148n, next()), =(149n, next()), =(150n, next()), =(151n, next()), =(152n, next()), =(153n, next()), =(154n, next()), =(155n, next()), =(156n, next()), =(157n, next()), =(158n, next()), =(159n, next()), =(160n, next()), =(161n, next()), =(162n, next()), =(163n, next()), =(164n, next()), =(165n, next()), =(166n, next()), =(167n, next()), =(168n, next()), =(169n, next()), =(170n, next()), =(171n, next()), =(172n, next()), =(173n, next()), =(174n, next()), =(175n, next()), =(176n, next()), =(177n, next()), =(178n, next()), =(179n, next()), =(180n, next()), =(181n, next()), =(182n, next()), =(183n, next()), =(184n, next()), =(185n, next()), =(186n, next()), =(187n, next()), =(188n, next()), =(189n, next()), =(190n, next()), =(191n, next()), =(192n, next()), =(193n, next()), =(194n, next()), =(195n, next()), =(196n, next()), =(197n, next()), =(198n, next()), =(199n, next()), =(200n, next()), =(201n, next()), =(202n, next()), =(203n, next()), =(204n, next()), =(205n, next()), =(206n, next()), =(207n, next()), =(208n, next()), =(209n, next()), =(210n, next()), =(211n, next()), =(212n, next()), =(213n, next()), =(214n, next()), =(215n, next()), =(216n, next()), =(217n, next()), =(218n, next()), =(219n, next()), =(220n, next()), =(221n, next()), =(222n, next()), =(223n, next()), =(224n, next()), =(225n, next()), =(226n, next()), =(227n, next()), =(228n, next()), =(229n, next()), =(230n, next()), =(231n, next()), =(232n, next()), =(233n, next()), =(234n, next()), =(235n, next()), =(236n, next()), =(237n, next()), =(238n, next()), =(239n, next()), =(240n, next()), =(241n, next()), =(242n, next()), =(243n, next()), =(244n, next()), =(245n, next()), =(246n, next()), =(247n, next()), =(248n, next()), =(249n, next()), =(250n, next()), =(251n, next()), =(252n, next()), =(253n, next()), =(254n, next()), =(255n, next()) )(), //////////////////////////////////////////////////////////////////////////////////////////////////, var(List, []()( var(head, 0), var(tail, 0), var(push, [](val, elem)( =(elem, Pair(val, Pair(tail))), not(head)([]()( =(head, =(tail, elem)) ), []()( tail(0, 1)(1, 1, elem), =(tail, elem) ))() )), var(pop, [](val)( =(val, tail(0, 0)), =(tail, tail(0, 1)(0, 0)), not(tail)([]()( =(head, 0) ), []()( tail(0, 1)(1, 1, 0) ))(), val )), var(unshift, [](val, elem)( =(elem, Pair(val, Pair(0, head))), not(head)([]()( =(head, =(tail, elem)) ), []()( head(0, 1)(1, 0, elem), =(head, elem) ))() )), var(shift, [](val)( =(val, head(0, 0)), =(head, head(0, 1)(0, 1)), not(head)([]()( =(tail, 0) ), []()( head(0, 1)(1, 0, 0) ))(), val )), var(forEach, [](func)( var(head, this .head), while([]()(head), []()( func(head(0, 0)), =(head, head(0, 1)(0, 1)) )), this )), var(this, [](prop)( ==(prop, .head)(head, ==(prop, .tail)(tail, ==(prop, .push)(push, ==(prop, .pop)(pop, ==(prop, .unshift)(unshift, ==(prop, .shift)(shift, ==(prop, .forEach)(forEach ))))))) )) )), //////////////////////////////////////////////////////////////////////////////////////////////////, var(String, [](byte)( var(list, List()), var(concat, [](str)( str .forEach([](byte)( list .push(byte) )), this )), var(clone, []()( var(str, String()), list .forEach([](byte)( str .append(byte) )), str )), var(write, []()( list .forEach([](byte)( writeByte(byte) )), this )), var(append, [](byte)( list .push(byte) )), bool(byte)(append)(byte), var(this, [](prop)( var(ret, 0), &&(not(ret), ==(prop, .head))([]()(=(ret, list .head)))(), &&(not(ret), ==(prop, .tail))([]()(=(ret, list .tail)))(), &&(not(ret), ==(prop, .push))([]()(=(ret, list .push)))(), &&(not(ret), ==(prop, .pop))([]()(=(ret, list .pop)))(), &&(not(ret), ==(prop, .unshift))([]()(=(ret, list .unshift)))(), &&(not(ret), ==(prop, .shift))([]()(=(ret, list .shift)))(), &&(not(ret), ==(prop, .forEach))([]()(=(ret, list .forEach)))(), &&(not(ret), ==(prop, .clone))([]()(=(ret, clone)))(), &&(not(ret), ==(prop, .append))([]()(=(ret, append)))(), &&(not(ret), ==(prop, .write))([]()(=(ret, write)))(), not(ret)([]()(=(ret, concat(prop))))(), ret )) )), []()( var(iter, Iterator(33n)), var(next, []()( String(iter()) )), =(_, String()), =(_newLine, String(10n)), =(_space, String(32n)), =(_!, next()), =(_", next()), =(_#, next()), =(_$, next()), =(_%, next()), =(_&, next()), =(_', next()), =(_openParen, String(40n)), =(_closedParen, String(41n)), next(), next(), =(_*, next()), =(_+, next()), =(_comma, String(44n)), next(), =(_-, next()), =(_., next()), =(_/, next()), =(_0, next()), =(_1, next()), =(_2, next()), =(_3, next()), =(_4, next()), =(_5, next()), =(_6, next()), =(_7, next()), =(_8, next()), =(_9, next()), =(_:, next()), =(_;, next()), =(_<, next()), =(_=, next()), =(_>, next()), =(_?, next()), =(_@, next()), =(_A, next()), =(_B, next()), =(_C, next()), =(_D, next()), =(_E, next()), =(_F, next()), =(_G, next()), =(_H, next()), =(_I, next()), =(_J, next()), =(_K, next()), =(_L, next()), =(_M, next()), =(_N, next()), =(_O, next()), =(_P, next()), =(_Q, next()), =(_R, next()), =(_S, next()), =(_T, next()), =(_U, next()), =(_V, next()), =(_W, next()), =(_X, next()), =(_Y, next()), =(_Z, next()), =(_[, next()), =(\\, next()), =(_], next()), =(_^, next()), =(__, next()), =(_`, next()), =(_a, next()), =(_b, next()), =(_c, next()), =(_d, next()), =(_e, next()), =(_f, next()), =(_g, next()), =(_h, next()), =(_i, next()), =(_j, next()), =(_k, next()), =(_l, next()), =(_m, next()), =(_n, next()), =(_o, next()), =(_p, next()), =(_q, next()), =(_r, next()), =(_s, next()), =(_t, next()), =(_u, next()), =(_v, next()), =(_w, next()), =(_x, next()), =(_y, next()), =(_z, next()), =(_{, next()), =(_|, next()), =(_}, next()), =(_~, next()) )(), //////////////////////////////////////////////////////////////////////////////////////////////////, var(readByte, []()( Byte( read(), read(), read(), read(), read(), read(), read(), read() ) )), var(writeByte, [](byte)( forEach(byte, write) )), var(writeDigit, [](byte)( writeByte(+(byte, 48n)) )), var(writeInt, [](byte)( gte(byte, 100n)([]()( writeDigit(/(byte, 100n)), writeDigit(%(/(byte, 10n), 10n)), writeDigit(%(byte, 10n)) ), []()( gte(byte, 10n)([]()( writeDigit(/(byte, 10n)), writeDigit(%(byte, 10n)) ), []()( writeDigit(byte) ))() ))(), byte ))
Adding two integers
[]()( var(space, 32n), var('0', 48n), var(num1, List()), var(num2, List()), var(mode, 0), while([]()( not(eof()) ), []()( var(byte, readByte()), eq(byte, space)([]()( =(mode, 1) ), []()( mode(num2, num1).push(byte) ))() )), var(num3, List()), var(carry, 0n), while([]()( ||(bool(num1 .head), bool(num2 .head)) ), []()( var(b1, not(=(b1, num1 .pop()))([]()( 0n ), []()( -(b1, '0') ))()), var(b2, not(=(b2, num2 .pop()))([]()( 0n ), []()( -(b2, '0') ))()), var(byte, +(carry, +(b1, b2))), =(carry, gt(byte, 9n))([]()( =(byte, -(byte, 10n)) ))(), =(carry, carry(1n, 0n)), num3 .push(byte) )), eq(carry, 1n)([]()( num3 .push(1n) ))(), while([]()( num3 .head ), []()( var(byte, num3 .pop()), writeByte(+(byte, '0')) )) )()
99 bottles of beer
[]()( var(comma, String() _comma _space), var(ofBeer, [](base)( base _space _o _f _space _b _e _e _r )), var(getWall, [](base)( base .clone() _space _o _n _space _t _h _e _space _w _a _l _l )), var(num, [](full, cap)( neq(bottlesNum, 0n)([]()( writeInt(bottlesNum) ), []()( bool(cap)(_N, _n).clone() _o _space _m _o _r _e .write() ))(), _space .write(), bool(full)([]()( plural()(_walls, _wall).write() ))() )), var(plural, []()( neq(bottlesNum, 1n) )), var(line1, [](cap)( num(1, cap), comma .write(), num(), plural()(_bottles, _bottle).write(), _. .write(), _newLine .write() )), var(line2, []()( comma .write(), num(1), _. .write() )), var(reset, []()( =(bottlesNum, 99n) )), var(_bottle, String() _b _o _t _t _l _e), var(_bottles, ofBeer(_bottle .clone() _s)), var(_wall, getWall(ofBeer(_bottle))), var(_walls, getWall(_bottles)), var(_and, String() _a _n _d), var(_take, String() _T _a _k _e _space _o _n _e) _space _d _o _w _n _space _and _space _p _a _s _s _space _i _t _space _a _r _o _u _n _d, var(bottlesNum), reset(), while([]()(neq(bottlesNum, 0n)), []()( line1(), =(bottlesNum, -(bottlesNum, 1n)), _take .write(), line2(), _newLine .write(), _newLine .write() )), line1(1), String() _G _o _space _t _o _space _t _h _e _space _s _t _o _r _e _space _and _space _b _u _y _space _s _o _m _e _space _m _o _r _e .write(), reset(), line2() )()
FizzBuzz
[]()( var(i, 1n), var(max, 100n), var(zz, String() _z _z), var(Fizz, _F _i zz), var(Buzz, _B _u zz), var(FizzBuzz, Fizz .clone() Buzz), var(first, 1), while([]()(lte(i, max)), []()( not(first)([]()( _newLine .write() ), []()( =(first, 0) ))(), var(%3, eq(%(i, 3n), 0n)), var(%5, eq(%(i, 5n), 0n)), &&(%3, %5)(FizzBuzz, %3(Fizz, %5(Buzz, _)) ).write(), not(||(%3, %5))([]()( writeInt(i) ))(), =(i, +(i, 1n)) )) )()
Quine
New lines added for readability. Does not need the header, unlike previous examples.
0,1,2,3,4,5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