From 457d70acda9b9c02ddb297fcb36ed1fa5b57f92a Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Tue, 5 Aug 2025 04:58:40 -0400 Subject: write some stuff about language goals --- doc/macros.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 doc/macros.txt (limited to 'doc/macros.txt') diff --git a/doc/macros.txt b/doc/macros.txt new file mode 100644 index 0000000..f39a30b --- /dev/null +++ b/doc/macros.txt @@ -0,0 +1,25 @@ +/* + * 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 } + } +} -- cgit v1.2.3