154 days ago · 7 min read1423 words · Tech · hide · Fediverse post

IntroductionThere is an RFC open on Rust which proposes what I’m calling hoisting expressions into the language. These are expressions which can be introduced inside of closures-only (for now), and are hoisted by the compiler to run before the rest of the closure does. To illustrate how they work, consider this example: rustprint!("hello "); hoist { print!("world!") };CopyEven though in the code we declared "hello " first and "world!" second, this will print: world!hello . In a way, you can think of hoist as the inverse of defer: defer in languages declare statements which are run after exiting the scope. hoist in Rust would declare expressions which are run before entering the scope. If you’re familiar with variable hoisting from JavaScript: this feature goes beyond that, not just hoisting variable (var) declarations to the top of the function, but hoisting the entire expression-evaluation to run before the rest of the closure. The proposal does not call it hoistRFC 3968 proposes the…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town