An esoteric programming language where everything is functions and strings, where the only built in operation is to interleave two strings.
Note
I need to work this out more.
The only allowed symbols non-negative integers and the symbols .
, ,
>
, <
, #
, !
and :
. Comments follow after any -
sign and any text there is ignored. Leading zeroes don't change the meaning of a symbol: 1
and 01
are considered identical.
All values are strings. The following things are built in ways to obtain strings.
0
is the empty string.- A
#
followed by a decimal number is a string of a single character whose unicode value is that number. For example,#72
is the string"H"
. ,10
gets 10 characters from the input. The string will be in reverse order.- If
1
and2
are strings,1 2
will interleave those strings.
Let A
and B
be strings, to compute A B
:
The first character will be A[0]
, the second character will be B[0]
, the third and fourth A[1]
and B[1]
respectively, and so on.
Whenever a string runs out of characters, the remaining characters of the other string will be simply applied in order.
"aaa" "bbb"
will be"ababab"
"aaa" "b"
will be"abaa"
"a" "bbb"
will be"abbb"
"aaa" ""
will be"aaa"
The interleave operation is left-commutative:
- `"aaa" "bbb" "ccc" = "acbcacbab"
Given a string S
, then to de-interleave it into two variables A
and B
(which start as empty strings), append the first character to A
, the second to B
, the third to A
, the fourth to B
, and so on, until all characters are distributed. When interleaving A
and B
, it must return S
again.
"aabb"
will become"ab" "ab"
"abababa"
will become"aaaa" "bbb"
A function can be defined by pattern matching:
- The pattern
1 2
will de-interleave the string into two variables1
and2
- The pattern
1
will simply put the whole input string into that variable1
- The pattern
0
will only match the empty string - Replacing any variable by a literal string will only match if that variable becomes that literal string
#72 2
will only match if, after de-interleaving, the left string equals"H"
. The input"Hai"
will not match but"Hi"
will.
The special function definition !
crashes the program, e.g. for invalid input. Instead of parentheses, (...)
, one must use inverted angle brackets, >...<
The function head
from haskell can be defined as follows:
10 : 0 : ! - If empty, no head
10 : 1 0 : 1 - Single character string, return that
10 : 1 2 : > 10 : 1 < - Multi character string, de-interleave and first character must be in the left side
The function tail
as follows:
11 : 0 : ! - If empty, no tail
11 : 1 0 : 0 - Single character string, return empty string
11 : 1 2 : 2 > 11 : 1 < - Multi character string, de-interleave, remove first character from left side, and interleave the other way around
To concatenate two strings, using above head and tail functions:
12 : 0 : 1 : 1 - Concatenating "" to B gives B
12 : 1 0 : 2 : 1 2 - Concatenating single char X to B gives X B, we can just use interleave
12 : 1 : 2 : > 10 : 1 < > 12 : > 11 : 1 < : 2 < - (head 1) `before` ((tail 1) `concat` 2)