Hi/Hallo Lukas,
Thank you for keeping TLBORM alive.
A suggestion of a sub-topic/related to #17, potentially fitting in/next to https://lukaswirth.dev/tlborm/decl-macros/building-blocks/counting.html:
Problem/Goal:
- Accept a variable number of actual/passed arguments (valid expressions).
- Do something with them (or don't - instead, do something with other variable(s), or inject some other code in, etc.)
- Pass those arguments (or something generated from them) to function/method call(s) or similar, in the same order.
The main problem is not storing argument(s) in a tuple, but accessing the tuple fields - generating the tuple numerical indexes. I couldn't find a way to do so: An integer expression generated as per your page above fails - to access tuple field(s), we can't just use a non-negative integer expression, so not anything like my_tuple.(1+2), but only literal, like my_tuple.3)!
So, instead of a flat tuple, I use a "tuple tree" (part of https://github.com/prudent-rs/prudent/tree/tuple_tree)
See https://github.com/prudent-rs/prudent/blob/tuple_tree/src/lib.rs#L71 and then see add_three and add_four (simple_examples/fn_add_three/src/main.rs and simple_examples/fn_add_four/src/main.rs).
use prudent::unsafe_fn;
unsafe fn add_four(left: u64, middle_left:u64, middle_right:u64, right: u64) -> u64 {
left + middle_left + middle_right + right
}
unsafe_fn!(add_four, 1, 2, 3, 4);
expands to:
use prudent::unsafe_fn;
unsafe fn add_four(left: u64, middle_left: u64, middle_right: u64, right: u64) -> u64 {
left + middle_left + middle_right + right
}
// ...
{
let (tuple_tree, fun) = ( (1, (2, (3, (4,)))), add_four );
#[allow(unsafe_code)]
unsafe {
fun(
tuple_tree.0,
tuple_tree.1 .0,
tuple_tree.1 .1 .0,
tuple_tree.1 .1 .1 .0,
)
}
};
```rust
Unfortunately, I don't have capacity to describe it/write on it more. If anyone has capacity/interest, please extract/reuse my macros, especially `unsafe_fn_internal_build_accessors_and_call`. You can also run `cargo test`.
UPDATE:
- use the GIT tag `tuple_tree`. This `tuple_tree` approach and the above examples are being removed from `master` branch soon. While this approach is a good one (if you do need such a tuple field access), I've realized a simpler solution to my problem/goal, where I don't need to access the tuple field at all (I only need to set them - that's a compile-time check in an `if false {...}` branch, work in progress).
- I hope that the macros themselves and their capturing variables are documented and named well enough, but again, only on `tuple_tree` GIT tag.
Hi/Hallo Lukas,
Thank you for keeping TLBORM alive.
A suggestion of a sub-topic/related to #17, potentially fitting in/next to https://lukaswirth.dev/tlborm/decl-macros/building-blocks/counting.html:
Problem/Goal:
The main problem is not storing argument(s) in a tuple, but accessing the tuple fields - generating the tuple numerical indexes. I couldn't find a way to do so: An integer expression generated as per your page above fails - to access tuple field(s), we can't just use a non-negative integer expression, so not anything like
my_tuple.(1+2), but only literal, likemy_tuple.3)!So, instead of a flat tuple, I use a "tuple tree" (part of https://github.com/prudent-rs/prudent/tree/tuple_tree)
See https://github.com/prudent-rs/prudent/blob/tuple_tree/src/lib.rs#L71 and then see
add_threeandadd_four(simple_examples/fn_add_three/src/main.rsandsimple_examples/fn_add_four/src/main.rs).expands to: