Beskew is variant of combinatory logic created by User:Arctenik, based on the idea of a very minimal language that can turn itself into any other language (or, at least, any other Unicode-based syntax). In Beskew, every Unicode character is a function (though the vast majority are formulaically defined as Church numerals), which theoretically allows a Beskew program to create a function that interprets its subsequent arguments as arbitrary program source code. Whether this is possible with any degree of time-efficiency has yet to be seen.
Since every character is a function, a Beskew program just consists of a sequence of implicit function applications. Like with usual combinatory logic notation, these function applications are left-associative –
abcd can be thought of as being grouped like
((ab)c)d (though note that the latter is an abstract notation that wouldn't work as Beskew code, since the parentheses would be interpreted as functions rather than grouping).
The only characters with especially unique behavior are
K, which represent the same functions that they do in the BCKW and SKI calculi:
- B binds three arguments, applies the second argument to the third argument, and passes the result of that to the first argument
- S binds three arguments, applies each of the first two arguments to the third argument, and passes the result of the second argument's application to the result of the first argument's application
- K binds two arguments and returns the first (or, equivalently, takes one argument
xand returns a function that consumes an argument and returns
All other characters represent Church numerals; any given character other than B, S, or K represents the Church numeral for that character's Unicode code point. For example,
% is a function that applies its first argument to its second argument 37 times, since 37 is the Unicode value of the percent sign.
Notation in this article
It's often very useful to use characters in Beskew programs for their numeric values, so for the sake of clarity and to allow control characters to be shown here, some characters in code examples may be replaced with the notation
n is the character's code point.
Additionally, when functions are being talked about more abstractly rather than in terms of actual Beskew code, parentheses may be used to represent grouping.
Line endings in example code should be assumed to be single-character.
In order to support input/output and parsing, a Beskew program has several additional arguments appended to it, in this order:
- The EOF symbol, defined as a function that binds ten arguments and returns the tenth
- The output function, described below
- The characters of the input stream, each interpreted as a function in the same manner as the program code (note that this means that the characters B, S, and K need to be handled specially)
- Another instance of the EOF symbol
The output function takes one argument, (potentially) produces output based on the argument, and returns the identity function. The argument must be (equivalent to) one of the three primitive combinators
K, a Church numeral, or the EOF symbol; the behavior for any other value is undefined. If the argument is the EOF symbol, no side effect happens; if the argument is a numeral, the character with that code point is added to output; and if the argument is a combinator, that combinator's name is added to output.
One relatively simple algorithm for distinguishing these five types of symbols is this:
q is the symbol is question,
w is a function that applies its second argument to its first argument,
r is a function that returns its third argument, and
e are functions that consume some number of arguments (4-0 respectively) and then return a function corresponding to the symbol's type (
S, numeral, or EOF, respectively).
In order for side effects to work in a useful way, Beskew must be lazily evaluated – an expression is never evaluated unless its result is needed (if only indirectly) in order to process the next character in the program/input (or theoretical character, if there aren't actually any further arguments). On the other hand, however, functions should also be evaluated as soon as they have the absolute minimum number of arguments; for example, although
 nominally takes two arguments since it's a Church numeral, it behaves equivalently to the identity function and so can be evaluated with only one argument.
There are no grouping symbols in Beskew, but grouping can be simulated by using numerals with the
S combinators. A grouped expression of the form
f(abcd...) can be simulated as
n is the length of
abcd..., and an expression like
(abcd...)(pqrs...) can be simulated as
n is the length of
m is the length of
A comment can be simulated with arguments to the function
n is the length of the comment:
K\\ This program prints a comet symbol BKSBSK☄
Additional examples may be found in the external resources.
......which is derived from this pair of abstract expressions (including a lambda expression written as
<output builder> = (L rpx.r(S(Sp)(Kx))) K(<output builder>Hello, world!)
The program builds up a function that that applies its final argument (the output function) to each of the characters in
Hello, world!, and is wrapped in a
K application in order to get rid of the first EOF symbol.
K\\ Derived from (L f.ff)(L fos.osffo) = K(S(B(SS)(B(BK)(S)))) BKSBSSBBBSSSBBBBKS
This program implements a Deadfish-like syntax within the program itself; the Deadfish code is written following the main program, with two preceding spacing characters. The main difference from actual Deadfish is that it outputs characters rather than numbers. However, the numeric operations are too slow (at least in the existing interpreter) to actually do much in a reasonable amount of time. The Deadfish code used here outputs a hash sign (Unicode value 35).
The expressions used to create this program can be found here.
Beskew is Turing-complete, as it's equivalent to a superset of SK calculus. (Even though there's a finite number of Unicode characters, which might seem to limit the grouping patterns that can be used, it's possible to create very large numbers in very few characters by applying one numeral to another – an operation equivalent to exponentiation. This would allow a smaller grouping operation to set up a larger grouping operation.)