1 -{ extension 'xmatch' }
4 function p(msg) io.write(msg..' ':rep(WIDTH-#msg)) end
6 ----------------------------------------------------------------------
7 p "match as an expression"
8 print(match 1 with 1 -> 'ok' | 2 -> 'KO')
10 ----------------------------------------------------------------------
11 p "global match function"
13 | x if x<10 -> return 'o'
18 ----------------------------------------------------------------------
19 p "global match function, multi-args"
21 | x, y if x<y -> return 'increasing'
22 | _, _ -> return 'decreasing'
25 if cmp(1,2)=='increasing' and cmp(2,1)=='decreasing' then
26 print "ok" else print "KO"
29 ----------------------------------------------------------------------
30 p "local match function"
32 local match function x
39 ----------------------------------------------------------------------
40 p "global bind assignment"
41 bind {a, b} = {'o', 'k'}
44 ----------------------------------------------------------------------
45 p "local bind assignment"
48 local bind {c, {d}} = {'o', {'k'}}
52 ----------------------------------------------------------------------
53 p "local bind assignment scope"