diff options
Diffstat (limited to 'spec/inputs/lists.mp')
-rw-r--r-- | spec/inputs/lists.mp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/inputs/lists.mp b/spec/inputs/lists.mp new file mode 100644 index 0000000..15eb9ab --- /dev/null +++ b/spec/inputs/lists.mp | |||
@@ -0,0 +1,72 @@ | |||
1 | |||
2 | hi = [x*2 for _, x in ipairs{1,2,3,4}] | ||
3 | |||
4 | items = {1,2,3,4,5,6} | ||
5 | |||
6 | _ = [z for z in ipairs items when z > 4] | ||
7 | |||
8 | rad = [{a} for a in ipairs { | ||
9 | 1,2,3,4,5,6, | ||
10 | } when good_number a] | ||
11 | |||
12 | |||
13 | _ = [z for z in items for j in list when z > 4] | ||
14 | |||
15 | require "util" | ||
16 | |||
17 | dump = (x) -> print util.dump x | ||
18 | |||
19 | range = (count) -> | ||
20 | i = 0 | ||
21 | return coroutine.wrap -> | ||
22 | while i < count | ||
23 | coroutine.yield i | ||
24 | i = i + 1 | ||
25 | |||
26 | dump [x for x in range 10] | ||
27 | dump [{x, y} for x in range 5 when x > 2 for y in range 5] | ||
28 | |||
29 | things = [x + y for x in range 10 when x > 5 for y in range 10 when y > 7] | ||
30 | |||
31 | print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2 | ||
32 | |||
33 | print "hello", x for x in items | ||
34 | |||
35 | _ = [x for x in x] | ||
36 | x = [x for x in x] | ||
37 | |||
38 | print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2 | ||
39 | |||
40 | double = [x*2 for x in *items] | ||
41 | |||
42 | print x for x in *double | ||
43 | |||
44 | cut = [x for x in *items when x > 3] | ||
45 | |||
46 | hello = [x + y for x in *items for y in *items] | ||
47 | |||
48 | print z for z in *hello | ||
49 | |||
50 | |||
51 | -- slice | ||
52 | x = {1, 2, 3, 4, 5, 6, 7} | ||
53 | print y for y in *x[2,-5,2] | ||
54 | print y for y in *x[,3] | ||
55 | print y for y in *x[2,] | ||
56 | print y for y in *x[,,2] | ||
57 | print y for y in *x[2,,2] | ||
58 | |||
59 | a, b, c = 1, 5, 2 | ||
60 | print y for y in *x[a,b,c] | ||
61 | |||
62 | |||
63 | normal = (hello) -> | ||
64 | [x for x in yeah] | ||
65 | |||
66 | |||
67 | test = x 1,2,3,4,5 | ||
68 | print thing for thing in *test | ||
69 | |||
70 | -> a = b for row in *rows | ||
71 | |||
72 | |||