@@ -43,11 +43,16 @@ pattern (bar (the):? [x is Foo]) precedence?
43
43
(x)/ (y)/ (z) # # alternation
44
44
45
45
# # 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
49
47
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
51
56
```
52
57
53
58
## Functions
@@ -57,22 +62,35 @@ fn functionName param param param
57
62
# # implicit return
58
63
nothing
59
64
60
- fn functionName (param is Foo) (param or default)
65
+ fn functionName (param is / matches Foo) (param or default)
61
66
# # is -> type restrictions: if the param does not match Foo it will throw a TypeError immediately
62
67
# # or -> default value if not provided
63
68
```
64
69
65
- ## Other built-in functions
70
+ ## Other built-in constructs
66
71
67
72
``` py
68
73
# # Import a module
69
74
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"
71
76
import [modname is String | Symbol] # # like Python "import foo"
72
77
73
78
# # 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
74
91
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"
78
96
```
0 commit comments