Files
bux-lang/examples/macro_twice.bux
T
dimgigov fe3b1e8b6a
ci / build (ubuntu) (push) Has been cancelled
ci / unit + fmt (push) Has been cancelled
ci / examples (push) Has been cancelled
ci / goldens + tools (push) Has been cancelled
ci / apps (push) Has been cancelled
ci / selfhost smoke (push) Has been cancelled
ci / macos smoke (push) Has been cancelled
ci / windows smoke (push) Has been cancelled
ci / CI gate (push) Has been cancelled
selfhost-loop / bootstrap determinism (push) Has been cancelled
feat: macros (multi-rep, hygiene), Drop field-move, lean multi-OS CI
Sessions 56–69: declarative macro! with rep/zip/literal/block and
unhygienic var $name binders; partial field-move skip Drop; @[Release]
polish; LSP type hierarchy; CI Nim cache + lean macOS + Windows smoke.
2026-07-20 17:19:46 +03:00

41 lines
873 B
Plaintext

// Declarative macro! + built-in quote! (session 59)
// Expands before type-check; $frags splice with call-site hygiene.
import Std::Io::{PrintLine};
import Std::String::{String_FromInt};
macro! twice {
($x:expr) => {
($x) + ($x)
}
}
macro! add2 {
($a:expr, $b:expr) => {
($a) + ($b)
}
}
func Main() -> int {
let a: int = twice!(21);
let b: int = add2!(10, 32);
// quote! is a built-in identity expand (call-site graft)
let c: int = quote!(a + 1);
PrintLine(String_FromInt(a));
PrintLine(String_FromInt(b));
PrintLine(String_FromInt(c));
if a != 42 {
PrintLine("FAIL twice");
return 1;
}
if b != 42 {
PrintLine("FAIL add2");
return 1;
}
if c != 43 {
PrintLine("FAIL quote");
return 1;
}
PrintLine("PASS macro_twice");
return 0;
}