hi = [x*2 for _, x in ipairs{1,2,3,4}] items = {1,2,3,4,5,6} _ = [z for z in ipairs items when z > 4] rad = [{a} for a in ipairs { 1,2,3,4,5,6, } when good_number a] _ = [z for z in items for j in list when z > 4] require "util" dump = (x) -> print util.dump x range = (count) -> i = 0 return coroutine.wrap -> while i < count coroutine.yield i i = i + 1 dump [x for x in range 10] dump [{x, y} for x in range 5 when x > 2 for y in range 5] things = [x + y for x in range 10 when x > 5 for y in range 10 when y > 7] print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2 print "hello", x for x in items _ = [x for x in x] x = [x for x in x] print x,y for x in ipairs{1,2,4} for y in ipairs{1,2,3} when x != 2 double = [x*2 for x in *items] print x for x in *double cut = [x for x in *items when x > 3] hello = [x + y for x in *items for y in *items] print z for z in *hello -- slice x = {1, 2, 3, 4, 5, 6, 7} print y for y in *x[2,-5,2] print y for y in *x[,3] print y for y in *x[2,] print y for y in *x[,,2] print y for y in *x[2,,2] a, b, c = 1, 5, 2 print y for y in *x[a,b,c] normal = (hello) -> [x for x in yeah] test = x 1,2,3,4,5 print thing for thing in *test _ = -> a = b for row in *rows with tb f [a] -- indexing f [a,] -- list with one element print v for v in *f[a,] -- table slicing in for-loop f [] -- empty list f[] = x -- table appending to f [a] = x -- assign to tb[a] [a,] = x -- list destructuring for x [] = x -- table appending to tb c = a in [1] -- check if a in tb[1] c = a in [1,] -- check if a == 1 c = a in {1} -- check if a == 1 c = a in {1,} -- check if a == 1 do [a, b] = hello [name = "nameless", job = "jobless"] = person do transactions = ["T001", "T002", "T003", "T004", "T005"] middleTransactions = transactions[2, -2] print middleTransactions -- => {"T002", "T003", "T004"} do logs = - start: 0, end: 100 - start: 100, end: 200 - start: 200, end: 123 print logs[#].end -- => 123 do pendingOrders = ["O001", "O002", "O003", "O004"] print pendingOrders[# - 1] -- => "O003" do getOrders = -> { { id: "O1001", status: "pending" } { id: "O1002", status: "processing" } { id: "O1003", status: "done" } } lastStatus = getOrders()[#].status assert lastStatus == "done" do cloneList1 = (list) -> list[,] cloneList2 = (list) -> [...list,] cloneTable = (tb) -> {...tb} do print( globalTB[#] a.b.c[# - 2] x?\y?!.z?[# - 3] ) do f = -> print( globalTB[#]\end 123 a.b.c[5,-5][# - 2] x?\y?!.z?[# - 3]?[, -3] ) nil