|
1 |
| -($ suffix-dup (sym x) { |
| 1 | +(macro suffix-dup (sym x) { |
2 | 2 | ($if (> x 1) (suffix-dup sym (- x 1)))
|
3 | 3 | ($symcat sym x) })
|
4 | 4 |
|
5 |
| -($ partial (func ...defargs) { |
6 |
| - ($ bloc (suffix-dup a (- ($argcount func) (len defargs)))) |
| 5 | +(macro partial (func ...defargs) { |
| 6 | + (macro bloc (suffix-dup a (- ($argcount func) (len defargs)))) |
7 | 7 | (fun (bloc) (func ...defargs bloc))
|
8 | 8 | ($undef bloc) })
|
9 | 9 |
|
|
15 | 15 | (print "Expected arguments for test_func1: " ($argcount test_func1) ", expected " 2)
|
16 | 16 | (print "Calling them: " (test_func 1 2 3) " " (test_func1 2 3))
|
17 | 17 |
|
18 |
| -($ foo (a b) (+ a b)) |
| 18 | +(macro foo (a b) (+ a b)) |
19 | 19 | (print "Using macro foo (a b) => (+ a b): " (foo 1 2))
|
20 | 20 |
|
21 |
| -($ var 12) |
| 21 | +(macro var 12) |
22 | 22 | (print "Using macro constant var=12: " var)
|
23 | 23 |
|
24 | 24 | ($if (= var 12)
|
|
29 | 29 | (print "This was executed in a if macro, testing (and true true)")
|
30 | 30 | (print "You shouldn't see this (bis)"))
|
31 | 31 |
|
32 |
| -($ defun (name args body) (let name (fun args body))) |
| 32 | +(macro defun (name args body) (let name (fun args body))) |
33 | 33 | (defun a_func (a b) (+ a b))
|
34 | 34 | (print "Generated a function with a macro, a_func (a b) => (+ a b)")
|
35 | 35 | (print "Calling (a_func 1 2): " (a_func 1 2))
|
36 | 36 |
|
37 |
| -($ one (...args) (print "Macro 'one', returns the 2nd argument given in " args " => " (@ args 1))) |
| 37 | +(macro one (...args) (print "Macro 'one', returns the 2nd argument given in " args " => " (@ args 1))) |
38 | 38 | (one 1 2)
|
39 | 39 | (one 1 3 4)
|
40 | 40 | (one 1 5 6 7 8)
|
41 | 41 |
|
42 |
| -($ last (...args) (print "Macro 'last', returns the last argument given in " args " => " (@ args -1))) |
| 42 | +(macro last (...args) (print "Macro 'last', returns the last argument given in " args " => " (@ args -1))) |
43 | 43 | (last 1 2)
|
44 | 44 | (last 1 3 4)
|
45 | 45 | (last 1 5 6 7 8)
|
46 | 46 |
|
47 | 47 | {
|
48 | 48 | (print "Testing macros in scopes and macro shadowing")
|
49 | 49 |
|
50 |
| - ($ test (+ 1 2 3)) |
| 50 | + (macro test (+ 1 2 3)) |
51 | 51 | (print "(global) Reading macro 'test', expected 6, " test)
|
52 | 52 |
|
53 | 53 | ((fun () {
|
54 |
| - ($ test (- 1 2 3)) |
| 54 | + (macro test (- 1 2 3)) |
55 | 55 | (print "(sub scope) Reading macro 'test', expected -4, " test) }))
|
56 | 56 |
|
57 | 57 | (print "(global) Reading macro 'test', expected 6, " test)
|
58 | 58 |
|
59 | 59 | {
|
60 |
| - ($ test 555) |
| 60 | + (macro test 555) |
61 | 61 | (print "(subscope) Reading macro 'test', expected 555, " test)
|
62 |
| - ($ undef test) |
| 62 | + ($undef test) |
63 | 63 | (print "(subscope, undef test) Reading macro 'test', expected 6, " test)
|
64 |
| - ($ undef a) } } |
| 64 | + ($undef a) } } |
65 | 65 | (print "Demonstrating a threading macro")
|
66 | 66 |
|
67 |
| -($ -> (arg fn1 ...fn) { |
| 67 | +(macro -> (arg fn1 ...fn) { |
68 | 68 | ($if (> (len fn) 0)
|
69 | 69 | (-> (fn1 arg) ...fn)
|
70 | 70 | (fn1 arg)) })
|
|
0 commit comments