Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoiding lambdas with capture #8

Open
majg0 opened this issue Sep 28, 2020 · 1 comment
Open

Avoiding lambdas with capture #8

majg0 opened this issue Sep 28, 2020 · 1 comment

Comments

@majg0
Copy link

majg0 commented Sep 28, 2020

Hi Raph! Great work!

At my work we use a custom language which does not support captures in lambdas. Instead we have simple definitions of semantic macros.

Reading the counter.rs source therefore had me wonder... how about an alternative API using begin/end calls instead? I assume the main reason for callbacks is safety: not missing a matching end call.

Matching begin/end using Rust macros might provide increased confusion in traces.
If we just don't enforce this at compile time, control flow could become visibly simpler and more open and powerful, not being coupled to function boundaries. This could also open up for more complex composition.

I think it's a tradeoff worth pondering, despite not necessarily being idiomatic Rust. What do you think?

I'm considering e.g. crashing at runtime if a node ends up unclosed, together with some simple API like cx.push(MyContainer::new()); { ... } cx.pop(); or something similar.

Would love to hear your thoughts on this!

@raphlinus
Copy link
Owner

We've gone back and forth on this a bunch. It used to be simple begin/end before f2d8733, which introduced the scoped closures. @maan2003 also explored a guard pattern in #1, but we came to the conclusion its drawbacks outweighed its advantages.

I'm personally reluctant to use macros where plain code can suffice, but this question of avoiding imbalance is a tough one.

It's possible there's a really good solution to this, but we might end up with going with the least bad thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants