blob: 7b3c6975e0bdc64e5356612b4026d2806b5425b1 (
plain)
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
|
/*
* dollar sign identifiers are only valid within a macro body (what i believe
* scheme folk call "hygienic")
*/
macro SWAP($a, $b) {
let $tmp = $a
$a := $b
$b := $tmp
}
proc foo(n ^Node) {
SWAP(&n^.in.data[0], &n^.in.data[1])
}
/*
* note that the macro body between the braces isn't a new scope, so you can
* still e.g. have a macro that defines a variable. or, perhaps, a function:
*/
macro V2OP($name, $op) {
func $name(a, b vec2) vec2 {
return vec2 { a.x $op b.x, a.y $op b.y }
}
}
V2OP(add, +)
V2OP(sub, -)
V2OP(mul, *)
V2OP(div, /)
|