From: Brendan Hansen Date: Sat, 30 Oct 2021 01:21:03 +0000 (-0500) Subject: added example of #() X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=90b8375a136431f42bff7ed4ea4f5843cd17b8f3;p=onyx.git added example of #() --- diff --git a/examples/18_macros.onyx b/examples/18_macros.onyx index 69bf03b1..383ca7d4 100644 --- a/examples/18_macros.onyx +++ b/examples/18_macros.onyx @@ -89,9 +89,9 @@ main :: (args: [] cstr) { // Because simple_code is a compile-time value, it can be passed to procedures as so: triple :: ($body: Code) { println("Running 3 times!"); - #insert simple_code; - #insert simple_code; - #insert simple_code; + #insert body; + #insert body; + #insert body; } triple(simple_code); @@ -100,12 +100,16 @@ main :: (args: [] cstr) { // compile-time parameter (the '$'). triple_macro :: macro (body: Code) { println("Running 3 times in a macro!"); - #insert simple_code; - #insert simple_code; - #insert simple_code; + #insert body; + #insert body; + #insert body; } triple_macro(simple_code); + + // As another small shorthand, if a code block only contains one expression (like the code block above), + // then you can write by wrapping the expression in #(...). + triple_macro(#(println("Short code block!"))); } #load "core/std"