blob: 5be560460632c96fc9fc4d8ce2f087e483ee4ff2 (
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
|
if assign / guard
=================
Swift has "if let", which makes the identifier accessible only inside
the "if" block, which is only entered if the value is not null.
Similarly, there is a "guard let", but in that case the value is
accessible only in the statements following the "guard".
Improvements
------------
"if let" is has a fairly obvious meaning, but type inference does not belong
in SLUL, so it should not be copied as-is.
"gaurd let", on the other hand, is in my opinion NOT very obvious, and you
have to read the manual. SLUL should strive to be as obvious as possible!
Syntax 1
--------
if Thing t = get_thing() {
t.do_stuff()
}
require Thing u = get_thing() else {
...
}
u.do_stuff()
Problems:
- The else might not be visible if the line is long!
- Multiple things may need to be tested!
Syntax 2
--------
Thing t = maybe get_thing() else goto fail
Thing u = maybe t.other_thing() else goto fail
Problems:
- What if multiple things can go wrong?
Thing t = maybe get_thing().other_thing(a / possibly_zero) else goto fail
|