-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdolla-op-syntax.edh
70 lines (50 loc) · 1.56 KB
/
dolla-op-syntax.edh
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
{
# some playful syntax with the low-precedence procedure call operator ($)
method when( pred ) {
interpreter whenThat'sTrue ( callerScope, affirmExpr )
if pred then callerScope.eval( affirmExpr ) else nil
}
method unless( pred ) {
interpreter unlessThat'sTrue ( callerScope, negatExpr )
if pred then nil else callerScope.eval( negatExpr )
}
}
# Note:
#
# - `$` is the low-precedence procedure call operator,
# similar to the same ($) operator (function application) as in Haskell
#
# - curly brackets quoting is not necessary for a single statement, but nice to
# have, for future sibling statements to be added
# this may be the most idiomatic form, it may help a bit if you build the
# intuition that those 2 `$` are quoting the condition, or if any of the `$`
# omitted, that's different semantic
{
when$ 3>2 ${
console.print( 'Math never lies.' )
}
unless$ 3 is 2 ${
console.print( "So it's trust worthy." )
}
}
# working form without the 1st `$`, but this may be anti-idiomatic:
# * if you forget the `$`, things go definitely wrong
{
when ( 3>2 ) ${
console.print( 'Math never lies.' )
}
unless ( 3 is 2 ) ${
console.print( "So it's trust worthy." )
}
}
# working form without `$` at all, but this may be anti-idiomatic:
# * if you forget the round brackets, things go definitely wrong
# * if you forget the curly brackets, it'll fail if you add a 2nd statement
{
when( 3>2 ) ( {
console.print( 'Math never lies.' )
} )
unless( 3 is 2 ) ( {
console.print( "So it's trust worthy." )
} )
}