Skip to content

Commit 893a58a

Browse files
Update syntax_ideas.md
1 parent 9085c7e commit 893a58a

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

dev_notes/syntax_ideas.md

+28-10
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ pattern (bar (the):? [x is Foo]) precedence?
4343
(x)/(y)/(z) ## alternation
4444

4545
## capturing
46-
[x is (Foo)]
47-
## --> captures x if it is an instance of Foo
48-
## or if Foo is callable and returns true when given x
46+
[x (Foo)] ## captures what Foo matches
4947

50-
[is Space] ## --> captures but doesn't bind
48+
[x is/matches (Foo)]
49+
## shorthand for [x [is/matches Foo]]
50+
## --> captures x if it is an instance of Foo (is)
51+
## or if calling Foo with x returns true (matches)
52+
53+
[is (Foo)] ## --> captures but doesn't bind
54+
55+
[is Space] ## special because implicit spaces don't match newlines, this explicit space does
5156
```
5257

5358
## Functions
@@ -57,22 +62,35 @@ fn functionName param param param
5762
## implicit return
5863
nothing
5964

60-
fn functionName (param is Foo) (param or default)
65+
fn functionName (param is/matches Foo) (param or default)
6166
## is -> type restrictions: if the param does not match Foo it will throw a TypeError immediately
6267
## or -> default value if not provided
6368
```
6469

65-
## Other built-in functions
70+
## Other built-in constructs
6671

6772
```py
6873
## Import a module
6974
import [modname is String | Symbol] for [exports is Record] ## like Python "from foo import bar, baz"
70-
import [modname is String | Symbol] as [name is Symbol] ## like Python "import foo as bar"
75+
import [modname is String | Symbol] for [name is Symbol] ## like Python "import foo as bar"
7176
import [modname is String | Symbol] ## like Python "import foo"
7277

7378
## Control flow
79+
while [condition any:+][is Space][body is Block]
80+
if [condition any:+][is Space][body is Block]
81+
82+
## Dynamic-wind but like Python context manager
83+
with [context-manager][is Space][body is Block]
84+
85+
## Synchronization
86+
synchronized [mutex][is Space][body is Block]
87+
88+
## Coroutines
89+
fork[is Space][body is Block] ## returns the coroutine which can be awaited
90+
await [coro is Coroutine] ## waits for the coroutine to finish and gets the return value
7491

75-
while [condition [is Object]:+][is Space][body is Block]
76-
if [condition [is Object]:+][is Space][body is Block]
77-
synchronized [mutex [is Object]:+][is Space][body is Block]
92+
## Continuations
93+
callcc[is Space][body is Block]
94+
## interestingly enough each function callframe is implicitly wrapped in this to implement "return"
95+
## and every loop is wrapped in TWO of these to implement "break" and "continue"
7896
```

0 commit comments

Comments
 (0)