alma icon indicating copy to clipboard operation
alma copied to clipboard

Provide a `do` term, which allows you to inject a statement into an expression

Open masak opened this issue 9 years ago • 1 comments

(Though we don't have statement prefixes in 007. It'll most likely just be a kind of term.)

Starting to notice a pattern — for each design decision where we say "007 does this in a simpler way than Perl 6", we can provide a language-mod/macro that re-instates the Perl 6 way. :smile:

In this case, do would allow things like the following:

my thing = (stuff // do return).foo();

In other words, do allows you to nest a statement right in the middle of an expression.

Note that, as a first conservative approximation, all statements that don't alter the control flow and can have an actual return value, will have the value None. So you won't be able to do fun stuff like build a retro ternary operator out of do and if. Sorry.

I had this idea when I started to re-read #7.

masak avatar Oct 04 '16 19:10 masak

Linking to this blog post, which I just discovered. A more palatable alternative to an IIFE.

The example with return in the OP won't work — nor will anything else which doesn't want a function boundary as part of the deal. Still, worth considering instead of "expensive" syntax.

masak avatar Jul 23 '25 05:07 masak