Skip to content

Commit a501414

Browse files
authored
Add comprehensive syntax reference documentation
1 parent bfd05d0 commit a501414

1 file changed

Lines changed: 118 additions & 0 deletions

File tree

‎docs/syntax-reference.md‎

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# syntax reference
2+
3+
I have tried to list
4+
every keyword, construct and alias...
5+
if it aint here it probably does not exist
6+
7+
## functions
8+
9+
| does what | syntax |
10+
|-----------|--------|
11+
| define a function | `to name(args)` / `can name(args)` |
12+
| define (alt keywords) | `def name(args)` / `function name(args)` |
13+
| lambda | `fn x => x * 2` / `take x => x * 2` / `lambda x => x * 2` |
14+
| return a value | `return x` / `give x` |
15+
16+
## printing n input
17+
18+
| does what | syntax |
19+
|-----------|--------|
20+
| print | `say x` / `show x` |
21+
| print (alt) | `print x` |
22+
| print to stderr | `esay x` |
23+
| read input | `input("prompt")` / `ask("prompt")` |
24+
25+
## variables
26+
27+
| does what | syntax |
28+
|-----------|--------|
29+
| assign | `x = 5` / `x is 5` / `x be 5` |
30+
| constant | `const x = 5` |
31+
| ignored words | `the`, `let` (e.g. `the x = 5` is just `x = 5`) |
32+
| delete | `del obj.field` / `del obj[key]` (attributes only not plain vars) |
33+
| assert | `check x == 5` (blows up if false) |
34+
35+
## classes
36+
37+
| does what | syntax |
38+
|-----------|--------|
39+
| define | `class Name` / `thing Name` / `structure Name` |
40+
| constructor | `to init(args)` (runs on `Name()`) |
41+
| make one | `Name()` / `make Name()` / `new Name()` |
42+
| inherit | `class Child extends Parent` |
43+
| parent init | `super(args)` |
44+
| field default | `has x = 5` inside the class body |
45+
46+
## conditionals
47+
48+
| does what | syntax |
49+
|-----------|--------|
50+
| if / else if / else | `if cond` / `elif cond` / `else` |
51+
| guard (no else!) | `unless cond` (= `if not cond`, guard only) |
52+
| match | `when x` ... `is value` ... `otherwise` |
53+
54+
## loops
55+
56+
| does what | syntax |
57+
|-----------|--------|
58+
| for loop | `for x in list` / `for each x in list` |
59+
| while loop | `while cond` |
60+
| until loop | `until cond` (loops while cond is false) |
61+
| counted loop | `repeat 5 times` |
62+
| infinite loop | `forever` (pair with `stop` or rip) |
63+
| break | `stop` |
64+
| continue | `skip` |
65+
| do nothing | `pass` |
66+
67+
## booleans n logic
68+
69+
| does what | syntax |
70+
|-----------|--------|
71+
| true | `true` / `yes` |
72+
| false | `false` / `no` |
73+
| logic | `and`, `or`, `not` (words not symbols man) |
74+
| nothing | `null` |
75+
76+
## errors
77+
78+
| does what | syntax |
79+
|-----------|--------|
80+
| try / catch | `try` ... `catch e` |
81+
| cleanup | `always` / `finally` |
82+
| raise | `throw x` / `error x` |
83+
84+
## modules
85+
86+
| does what | syntax |
87+
|-----------|--------|
88+
| import | `import mod` / `import mod as m` |
89+
| selective | `from mod import name` |
90+
91+
## concurrency
92+
93+
| does what | syntax |
94+
|-----------|--------|
95+
| run in background | `t = spawn f()` |
96+
| wait for it | `await t` |
97+
| channel | `chan_open()` / `chan_send(ch, x)` / `chan_recv(ch)` / `chan_close(ch)` |
98+
| lock | `create_lock()` / `lock_acquire(l)` / `lock_release(l)` |
99+
100+
## types
101+
102+
| what | syntax |
103+
|------|--------|
104+
| number | `42`, `3.14` (everything is 64 bit float) |
105+
| string | `"hi"` or `'hi'` |
106+
| list | `[1, 2, 3]` |
107+
| dict | `{"a": 1}` |
108+
109+
## operators
110+
111+
| does what | syntax |
112+
|-----------|--------|
113+
| arithmetic | `+ - * / % **` (`/` is always float, `**` is power) |
114+
| comparison | `== != < > <= >=` |
115+
| compound assign | `+= -= *= /=` |
116+
| membership | `in` / `not in` |
117+
118+
that should be everything i hope...

0 commit comments

Comments
 (0)