blob: 8b93973a53e35a9d0fa832eb3ee436c453a5be19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
Sentinel values
===============
Sentinel values are basically a way to combine an enumeration (that is,
`only`-values in SLUL) with a reference to an object.
There are (at least) two ways to implement sentinel (constant singleton)
values:
* Per type definition
* Per type reference
Per type definition
-------------------
Example:
# Class "File"
sentinels
Invalid "" None
String filename
?Int fd
constructor new
String filename
?Int fd
...
Example of "per reference definition"
-------------------------------------
Example:
# Class "ErrorKind"
only
NotFound
ConnectionError
ResponseError
# Class "ExampleClass"
func get_value
...
return
SomeObject (or ErrorKind) file
I think "per reference definition" might be better?
This could also be extended to allowed for multiple enums:
(but this will only work if all but the first are closed enums)
SomeObject (or FileErrorKind NetErrorKind)
Or specific enum items:
SomeObject (or ErrorKind.NotFound)
And it could be used to replace option-types/None:
(perhaps `?` could be a shorthand for it?)
SomeObject (or Optional.None)
Limitations
-----------
The enum values must not collide with valid pointer vlues on ANY
current or future supported platform.
|