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
|
--- sugar for making pl.List work like Python lists.
-- The list macro is a factory which generates macros which 'shadow' the variable
-- and kick in when they are followed by [...].
require_ 'list'
-- the two forms of 'list' initialization
-- (altho it grabs values upto '\n', this only happens outside a () or {},
-- so multi-line initializations are possible
list ls,lo = {10,20,30},{'A','ay',
'B','C'}
list two
-- the above statements created both the macros 'ls' and values 'ls', etc.
two:append(1)
two:append(2)
-- seen as plain table access
print(ls[2])
-- special treatment for slice notation
print(ls[1:2])
-- if we are on the LHS, then adjust accordingly
ls[1:2] = {11,21,22}
print(ls[2:])
print(ls, two, lo)
-- like in Python, this makes a copy of all of the list
print(ls[:])
|