blob: 46026e0ce8ab50e065f4956e5991f7c3ef4fec89 (
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
var/mutability syntax
=====================
How to indicate...:
* that a variable value can be "replaced" / "pointed to something else"?
* that what the variable references can be modified?
* that a function call replaces:
- a parameter?
* that a function call modifies:
- it's object?
- a parameter?
* that a function can perform I/O?
* that a variable's type's method's can perform I/O if declared as
being able to do so?
Current solution
----------------
The current SLUL-try2 code uses the `!` character as a sigill, but there
are some minor issues with that:
* sigills such as `!` for modifiability and `@` for I/O might not be
intuitive? On the other hand, you're going to see `@File` almost everytime
you see something-`File`, so it might be something you learn easilly by
memorization (similar to how many human languages have different grammar
(often called "gender") for different words).
* it doesn't support out-parameters (but this might be a non-issue
with multiple return values)
Syntax options
--------------
var T var o
var T io f
a single keyword placed in different places
replaceable modifiable T o
replaceable io T f
different intuitive keywords (but those are quite long)
mrvar T o
irvar T f
different keywords distinguished by prefix letters
var mut T o
var io T f
synonym keywords with non-intuitive difference
!T !o
@T !f
sigills
VarT !o
IOT !f
type prefixes + identifier sigills
VarT varO
IOT varF
type prefixes + identifier prefixes
!T o <- ...
@T f <- ...
type sigills + different operators (`=` vs `<-`)
var T o <- ...
io T f <- ...
keywords + different operators (`=` vs `<-`)
var T o <- ...
io T f <- ...
replaceable keywords + different operators (`=` vs `<-`)
var T o..
io T f..
var T o = nonfinal ...
io T f = nonfinal ...
is there a shorter keyword?
nonfinal
changeable
changable
replacable
nonlast
temp
vary (...but confusingly similar to var)
var T o nonfinal
io T f nonfinal
# Alternative solution with 3 modes
var int i
modifiable T a
replaceable T b
replaceable modifiable T c
Old stuff
---------
Regarding <- syntax:
1. How to distinguish between replaceable vs non-replaceable
variables when there's no initial value?
- Maybe the variable could start out as "replaceable".
- Pros: Flexible.
- Cons: It becomes harder to mentally analyze code.
- Or require an explicit `<- unset` for replaceable variables?
- This might actually be somewhat readable as well.
2. How to distinguish between replaceable vs non-replaceable
fields?
- Could also have initial values (including `<- unset`).
(Maybe this is actually quite logical, as everything
else will have to be initialized in the constructor.)
Regarding += and array/map element assignment:
# How to distinguish between final and non-final assignment?
a += 1
arr 1 = 1
map k v += 1
Assigning to a field or element (or anything else that's not a plain local
variable) is always a non-final assignment.
But how should the syntax be?
... maybe <- is better?
Maybe <- could be tokenized as < - if it doesn't appear in an assignment?
But how about e.g. `a <- b <- c` ? Someone might write that, and then it
wouldn't do what you expected.
And this still doesn't solve the issue with +=
|