-
-
Notifications
You must be signed in to change notification settings - Fork 4
indexing
Pannous edited this page Dec 10, 2022
·
11 revisions
Angle offers
-
zero based indexing (a b c)[1] == b
-
one based indexing {a b c}#2 == b
-
map field object accessors:
-
{a:1 b:2}[a] == 1
-
{a:1 b:2}.a == 1
-
a in {a:1 b:2} == 1
-
a of {a:1 b:2} == 1
Bracket indexing is as a general rule close to metal: "abc"[1]='B' manipultates the byte sequence blindly, whereas "abc"#2="β" sets the character unicode safely.
The bracket version allows complex expressions, whereas '#' 'in' and 'of'
bind tightly, so
1 + 1 in {1:2} == 1 + {1:2}['1'] == 1+2
TODO: REALLY ?
1 + 1 in {1:3} == (1+1) in {1:3} == false
Solution: compiler error: mixing indexing and expressions needs grouping
{a:1 b:2}[a]
is related to pattern matching and evaluation
{a:1 b:2}(a)