From 90b8375a136431f42bff7ed4ea4f5843cd17b8f3 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 29 Oct 2021 20:21:03 -0500 Subject: [PATCH] added example of #() --- examples/18_macros.onyx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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" -- 2.25.1