blob: ea09d494afeda9c12fa9c088bc5f4ba842188308 (
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
Syntax test 1
func add_numbers
Int a
Int b
Int return
code
...
func multi_return
Int a
Int b
[Int String] return
Syntax test 2
func add_numbers
Int a
Int b
return Int
code
...
func multi_return
Int a
Int b
return [Int String]
Syntax test 3
func Int add_numbers
Int a
Int b
code
...
func [Int String] multi_return
Int a
Int b
- Avoids possibly confusing "return" keyword in definition
- Similar to how other languages do it
- Similar to the syntax at the call-site
- Grepping for functions becomes slightly harder
but still easy: grep -E '^func.* add_numbers$'
- Possibly harder to visually scan the source code.
- Type inferrence:
- Type-inferred functions do not specify the returns
- No distinction between type-inferred 0-return and 0-arg 0-return funcs.
- The `code` keyword is still required for type-inferred functions
- Could have an explicit "void" keyword:
`void`, `[]`, ...
- Or could do it similar to Pascal with `func` and `proc`.
- Or the Ada way and have mutation = no return.
- No obvious way to document the return value.
But it could be solve with the following convention.
And in simple cases, only a "Returns ..." line might be needed.
func [Int String] multi_return
# Converts the arguments to ....
#
# Returns the ...
Int a # ...
Int b # ...
Syntax test 4:
func Int add_numbers
Int a
Int b
code
...
Syntax test 5:
func Int add_numbers
| Int a
| Int b
code
...
Syntax test 6:
func add_numbers
param Int a
param Int b
return Int
code
...
Possible short syntax with type-inference (not for cross-module use):
func add_numbers
a b -> sum
code
...
func multi_return
a b -> num str
code
...
Sections or goto or something else?
-----------------------------------
Sections:
func f
Int x
Int y
code
...
goto work
section work
...
section end
...
Goto (how can it work without `end`?)
func f
Int x
Int y
code
...
for a in arr
if x == 0
if a == y
goto t
...
target t
Goto syntax 1:
if a == y
goto t
...
target t
Goto syntax 2:
if a == y
goto t
...
--->t
Flow-goto syntax 1:
block
if a == y
goto t
...
section t
...
Allow `section` in all block statements?
Disallow it at the top level?
Should goto into a block be allowed?
goto inside
...
block
section inside
...
|