Skip to content

Commit 63ce3c8

Browse files
committed
upd
1 parent 1136cf4 commit 63ce3c8

8 files changed

Lines changed: 29 additions & 39 deletions

File tree

TODO

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
- [ ] Equality allows mixing compatible operands with void and/or null.
8989
- [ ] Call operator
9090
- [ ] Base is passed *followedByCall=true*
91-
- [ ] Watch for static `meta::call` when calling classes (supports multiple signatures too)
91+
- [ ] Watch for class-self-attached `meta::call` when calling classes (supports multiple signatures too)
9292
- [ ] Perform type inference for omitted generic parameters.
9393
- [ ] `T(v)` cast - Semantic patch: Exclude null and/or undefined from T
9494
- [ ] `v is T` operator
@@ -138,6 +138,7 @@
138138
- [ ] If let statement
139139
- [ ] For non-nullable assignment, ensure test is not an accidental binding of a function/method (where the user meant to "call" it)
140140
- [ ] Apply non-nullability to type annotation if any
141+
- [ ] Provide context type for algebraic matching pattern
141142
- [ ] `for each`: `Iterator` and `Iterable` are iterable
142143
- [ ] `switch type`
143144
- [ ] Provide context type for type inference on `case(...)` parameters when matching over an algebraic enumeration
@@ -319,7 +320,7 @@
319320
- [ ] `clone()` returns the same ContextReference reference back without cloning
320321
- [ ] XML
321322
- [ ] Implement `Iterable`
322-
- [ ] static `meta::call(arg:*):XML`
323+
- [ ] self-attached `meta::call(arg:*):XML`
323324
- [ ] `meta::has(name:QName):boolean`
324325
- [ ] `@` prefix in name = attribute
325326
- [ ] `meta::get(index:int):XML` (throws if out of bounds)
@@ -329,7 +330,7 @@
329330
- [ ] `sibling(n)` - e.g. `sibling(-1)` (previous) and `sibling(1)` (next) - uses `parent` internally.
330331
- [ ] Attributes
331332
- [ ] XMLList
332-
- [ ] static `meta::call(arg:*):XMLList`
333+
- [ ] self-attached `meta::call(arg:*):XMLList`
333334
- [ ] XMLContext
334335
- [ ] Represent this as a class and not a record type (object literal works on classes now)
335336
- [ ] ignoreWhitespace defaults to true, which means "trim any whitespace at the beginning and end of text nodes". Unlike AS3/E4X, XML literals always ignore whitespace. (If whitespace is desired on text nodes, use interpolation.)

src/algebraic-enums.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Algebraic enumerations
22

3-
Algebraic enumerations, as opposed to simple enumerations, contain `type X()` definitions instead of just `const X` definitions; they desugar to an one-level hierarchy of classes, with the enum being an abstract class.
3+
Algebraic enumerations, as opposed to simple enumerations, contain `type X()` definitions instead of just `const X` definitions; they desugar to an one-level hierarchy of classes, with the enum being an abstract class, and each variant into a class with a self-attached `meta::call` method (so you can specify either the defined signature, or an object literal).
44

55
## Example
66

77
```sx
8-
package com.q.calculator {
8+
package no.calculator {
99
public enum Exp {
1010
/**
1111
* @param left Left-hand side.
@@ -17,26 +17,20 @@ package com.q.calculator {
1717
}
1818
}
1919
20-
import com.q.calculator.*
20+
import no.calculator.*
2121
22-
// type inference -
23-
// use a basemost lexical name
22+
var exp : Exp
2423
25-
// each variant implements a meta::call multi-method,
26-
// so it can accept values in different ways.
27-
var exp : Exp = Empty()
28-
var exp : Exp = Plus({ left: x, right: y })
29-
var exp : Exp = Plus(x, y)
24+
exp = Empty()
25+
exp = Plus({ left: x, right: y })
26+
exp = Plus(x, y)
3027
3128
switch type (exp) {
32-
case ({ value } : Number) {
33-
//
29+
case (Number(value)) {
3430
}
35-
case ({ left, right } : Plus) {
36-
//
31+
case (Plus(x, y)) {
3732
}
38-
case ({} : Empty) {
39-
//
33+
case (Empty()) {
4034
}
4135
}
4236
```

src/conversions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This section describes which type conversions are available.
44

5-
Explicit conversions may occur as either `T(v)` (strict conversion) or `v as T` (optional conversion). The behavior of the call operator over a type may not always be a conversion depending on if `T` implements the static `meta::call()` hook.
5+
Explicit conversions may occur as either `T(v)` (strict conversion) or `v as T` (optional conversion). The behavior of the call operator over a type may not always be a conversion depending on if `T` implements the self-attached `meta::call()` hook.
66

77
```sx
88
v as T // returns T?. failure returns null

src/lang-statements/switch-statements.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Switch statements
22

3-
The switch statement is similiar to that of Java. Unlike in Java, the switch statement does not include fallthroughs.
3+
The **switch** statement is similiar to that of Java. Unlike Java, the switch statement does not include fallthroughs.
44

55
```sx
66
switch (v) {
@@ -16,21 +16,18 @@ The **switch type** statement is used to match the type of a discriminant value.
1616

1717
```sx
1818
switch type (v) {
19-
case (d : double) {
20-
// double
19+
case (d : Date) {
2120
}
2221
default {
23-
// no matching case
2422
}
2523
}
2624
```
2725

28-
The **switch type** statement also supports matching algebraic data type variants, typically omitting the case's type annotation.
26+
The **switch type** statement also supports pattern matching on algebraic data types.
2927

3028
```sx
3129
switch type (exp) {
3230
case (Plus(10, right)) {
33-
//
3431
}
3532
}
3633
```

src/meta-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## meta::call()
66

7-
A static `meta::call()` method may be defined with any number of parameters and any result type, overriding the behavior of calling the class object.
7+
A class self-attached `meta::call()` method may be defined with any number of parameters and any result type, overriding the behavior of calling the class object.
88

99
```sx
1010
meta static function call():T {}

src/overview/language-comparison/as3.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,20 @@ switch (v) {
177177

178178
## Switch type
179179

180-
The `switch type` statement allows for simple type matching:
180+
The `switch type` statement allows for type and pattern matching:
181181

182182
```sx
183183
switch type (v) {
184184
case (d : Date) {
185-
//
186185
}
187186
default {
188-
//
187+
}
188+
}
189+
190+
switch type (exp) {
191+
case (Plus(x, y)) {
192+
}
193+
case (Nothing()) {
189194
}
190195
}
191196
```

src/overview/namespace-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Namespace methods
22

3-
A `class` that implements the static `meta::call` hook may act as a *namespace method*.
3+
A `class` that implements the self-attached `meta::call` hook may act as a *namespace method*.
44

55
```sx
66
package zero.fn {

src/overview/type-matching.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ v is T
1010

1111
```sx
1212
switch type (v) {
13-
case (regex : RegExp) {
14-
trace("a regex");
15-
}
16-
case ([x, y] : [double, double]) {
17-
trace("a tuple of double");
13+
case (d : Date) {
1814
}
1915
default {
20-
trace("any other");
2116
}
2217
}
2318
```
@@ -27,7 +22,6 @@ switch type (v) {
2722
```sx
2823
switch type (exp) {
2924
case (Plus(10, right)) {
30-
//
3125
}
3226
}
3327
```
@@ -36,6 +30,5 @@ switch type (exp) {
3630

3731
```sx
3832
if (let Plus(10, right) = exp) {
39-
//
4033
}
4134
```

0 commit comments

Comments
 (0)