#counter #with #u32 #bool #10 #eprocedural #init-counter #init-flag #update-counter #update-flag

macro eprocedural

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

2 releases

0.1.1 Mar 8, 2025
0.1.0 Mar 8, 2025

#495 in Procedural macros

Download history 166/week @ 2025-03-03 64/week @ 2025-03-10 7/week @ 2025-03-17

237 downloads per month

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

~195–620KB
~15K SLoC