- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.lua
More file actions
Latest commit
59 lines (52 loc) · 1.56 KB
/
Copy pathtest.lua
File metadata and controls
59 lines (52 loc) · 1.56 KB
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
localmap=require"maparray";
localL=map.wrap;
-- make a copy of the given table
localfunctioncp(tbl)
localt= {};
fork, vinpairs(tbl) dot[k] =vend;
returnt;
end;
localinteger= {0, 1, 2, 3, 4, 5};
-- print out the table content
localfunctionwrite(tbl)
fori=1, #tbl, 1do
io.write("\t", tostring(integer[i]), " -> ", tostring(tbl[i]), "\n");
end;
end;
--[[
local city = {
{ ["name"] = "Helsinky" },
{ ["name"] = "Riga" },
{ ["name"] = "Moscow" },
{ ["name"] = "Rome" },
{ ["name"] = "Washington" },
{ ["name"] = "Grozny" },
};
l = L "<" (L(1)["name"], L(2)["name"]);
_ = function(...) return l(...) end;
table.sort(city, _);
for i = 1, #city, 1 do print(i, city[i]["name"]) end;
--]]
io.write"negations of squares:\n"
write( map.map(cp(integer), -L() *L()) );
io.write"letter equivalents:\n"
write( map.map(cp(integer), L(string.char, L() + ("A"):byte()) ) );
io.write"map even integers:\n"
write( map.map(cp(integer), 1-L() %2) );
io.write"map even integers yielding booleans:\n"
write( map.map(cp(integer), L"==" (1-L() %2, 1)) );
io.write"format sequence output with a map function:\n"
write( map.map(cp(integer), "Integer #" .. (L() +1) ..": " ..L() ..";" ) );
--[[
-- same examples with regular Lua syntax:
write( map.map(cp(integer), function(v) return - v * v end) );
write( map.map(
cp(integer),
function(v) return string.char(v + ("A"):byte()) end
) );
write( map.map(cp(integer), function(v) return 1 - v % 2 end) );
write( map.map(
cp(integer),
function(v) return "Integer #" .. (v + 1) .. ": " .. v .. ";" end
) );
--]]