Beautiful is better than ugly,
For true elegance lies in expressive density.
Explicit is better than implicit,
Yet clarity is born from contextual coherence.
Simple is better than complex,
But the highest simplicity is the unification of ideas, not the poverty of symbols.
It is better for one symbol to hold three meanings,
Than for three new symbols to be born;
But each meaning must be reachable and unambiguous in its place.
Precision is superior to approximation.
To express falsehood through negation is a mark of semantic completeness.
Types are constraints that liberate; boundaries that define freedom.
Ambiguity is the enemy.
Yet there may be many paths to the same truth,
Each revealing a different aspect of understanding.
Within the universe of rationals, every integer is a fraction.
Within the realm of sequences, every structure is a list.
Namespaces are not entities;
Classes are but recurring patterns.
The machine is real -- our abstractions are its language.
-1 is commonly used for False (instead of 0, but 0 itself is still falsy).$.[} This is a comment. {].| Token | Meaning |
|---|---|
[ ... ] |
List |
( ... ) |
String (list of characters) |
{ ... } |
Code block |
\ + token |
Escaped token |
@x |
Character literal (\@n for newline, \@t for tab) |
| Numbers | Positive integer, 0, or fraction (e.g., 3\4 for 3/4) |
| TypeString | Type representation (see ยง7) |
Instructions marked with a star (*) are not allowed to be redefined.
| Instruction | Meaning | Example | |
|---|---|---|---|
#ab* |
a = b, evaluates to b. Use \#ab for declaration. |
#x 5 = let x = 5 |
|
+ab |
a+b, or a[b]. Pair b used as slice. |
+[1 2 3]1 = 2 |
|
-a |
Negation, or reverse list/string/pair. | -[1 2 3] = [3 2 1] |
|
*ab |
Multiplication, repetition, or type conversion. | *2 3 = 6 |
|
/a |
Reciprocal. | /4 = 1/4 |
|
%ab |
Modulo (a % b), or indexes of occurrences. |
%5 2 = 1; %(abac)@a = [0 2] |
|
|ab* |
Try execute a; if fail, execute b. |
||
=ab |
Equality test. | =2 3 = -1 (False) |
|
?abc* |
Ternary: if a then b else c. |
?1 x y = x |
|
~abc* |
For loop: for b in a: c. |
~list i func i |
|
.a |
Print a. |
.5 = prints 5 |
|
`ab |
Decimal expansion of a to b digits. Or type check if b is a type / floor(x) if b is Null. |
`1\3 5 = 0.33333 |
|
,* |
Get character from stdin. | ||
:* |
Get number from stdin. | ||
<a* |
Former/numerator/length/ASCII or basic form of a custom typed object. | <[1 2 3] = 3 |
|
>ab |
Compare: 1 if a>b, 0 if a=b, -1 if a<b. | ||
&ab |
Random integer in [a, b). Or choose b items in a. | &0 5 = random 0~4 |
|
;* |
Null. | ||
^ab* |
Make pair. | ^2 3 = (2,3) |
|
'ab* |
While loop. Evaluates to the each values of the body. | 'cond body |
" prefix)| Instruction | Meaning |
|---|---|
">a |
Convert to string. |
"<a |
Evaluate a. |
"*ab |
Substring search: indexes of all occurrences; or floor division (a // b). |
"%abc |
Split a by b. If c is not Null, split at most c times. |
":abcd |
Replace a[b:b+c] with d. (C++'s replace) / replace first d occurrences of b in a with c. If d is Null, replace all. (Python's replace) |
"~abc* |
Filter a for elements (assigned to b) that satisfy c. |
"!abcde* |
Initialize a with b, for d in c let a be e. Return a. |
"+abc |
Range. Start from a, end at b exclusive, step c. |
",a |
Get the content of a file as string (or GET request if a is a URL). If no file, return Null. |
".ab |
Rewrite file a with b (or POST request if a is a URL). If no file, create it. |
"$a |
Delete file a. |
"/a |
Execute system command a or sleep(a)(number). |
"|ab |
Raise an error called a with message b. |
!.!name param1 type1 param2 type2 ... body!map list\\l func\\f2 ~list i func i
!.x\\n{ [} Custom print {] }
"typeName.
!Point\\pnn
!"Point x\\pnn x
"Point ^2 3 [} Converts from pair to Point {]
To call a function, just write its name followed by its arguments. No other symbols are needed.
$name TypeString$Point\\pnn (pair of numbers).\\.| Symbol | Meaning |
|---|---|
n |
Number |
l |
List |
LX |
List (Typed; one sub-TypeString, no leading \) |
c |
Character |
fN |
Function with N args |
t |
Type |
pXY |
Pair (two sub-TypeStrings, no leading \) |
x |
Wildcard (Any type) |
q |
Null |
\name\ |
Already defined type |
Note that \\\x\ is reserved for system commands, as you could directly write the name.
| From = To | Number | List | Character | Pair | Type |
|---|---|---|---|---|---|
| Number a/b | - | [0 1/b 2/b ... a/b] |
chr(int(a/b)) |
(a,b) |
\n |
| List a | len(a) |
- | TypeError | (a[0],a[-1]) |
\l |
| Character a | ord(a) |
TypeError | - | (ord(a),a) |
\c |
| Pair a | a.former/a.latter |
[a.former a.latter] |
TypeError | - | \pXY |
| Type | TypeError | TypeError | TypeError | TypeError | \t |
| Null | NaN | [] |
'\0' |
(Null, Null) |
\q |
Other types : TypeError.
Like C++, we have commands for preprocessors.
| Command | Meaning |
|---|---|
\\\+filename\ |
#include <filename> |
\\\#string\ |
#define string |
\\\$string\ |
#undef string |
\\\!string\ |
#ifdef string |
\\\?string\ |
#ifndef string |
\\\.!string\ |
#elif defined(string) |
\\\.?string\ |
#elif !defined(string) |
\\\.\ |
#else |
\\\@\ |
#endif |
.(Hello, world!
)
!map list\\l func\\f1 ~list i func i