#proc #defines #call #arguments #implicit #counter #flags

macro eprocedural

create proc!()s and call them, passing in implicit arguments using with!()

2 releases

new 0.1.1 Mar 8, 2025
0.1.0 Mar 8, 2025

#531 in Procedural macros

MIT/Apache

8KB
132 lines

I once prototyped a language that looked somewhat like the following:

func main [
    init_counter
    init_flag

    while flag [
        update_counter
        update_flag
    ]
]

proc init_counter [
    exp counter := 10
]

proc init_flag [
    exp flag := true
]

proc update_counter with counter [
    counter--
]

proc update_flag with counter, flag [
    if counter == 0 [
        flag = false
    ]
]

and decided to try implementing a similar 'thing' in rust

use eprocedural::*;

proc!( init_counter {
    let counter = 10;
} defines counter: u32);

proc!( init_flag {
    let flag = true;
} defines flag: bool);

proc!( update_counter with counter: u32 {
    *counter -= 1;
});

proc!( update_flag with flag: bool, counter: u32 {
    if *counter == 0 {
        *flag = false
    }
});

fn main() {
    with!(init_counter);
    with!(init_flag);

    while flag {
        with!(update_counter);
        with!(update_flag);
    }
}

not smart enough for auto type checking though :/

Dependencies

~215–660KB
~16K SLoC