I think what you're suggesting is handled (verbosely, but generally) by given.
Well, the whole point here is of having an agile syntax, and I don't see how given could be used easily to achieve that. Care to give an example anyway?
| [reply] [d/l] |
I didn't state my point well. What you appear to be suggesting is a special case of what given does: topicalize something so you can both test and reuse it. I understand the usefulness of defined-or, and I understand the usefulness of given, but I don't see the need for something in-between.
I say this notwithstanding that some time ago I mused on a similar (not identical) notion. It didn't generate much excitement, either.
I haven't gotten much into Perl6, myself, so I can't even translate your example into a given construct, not that it would be excitingly terse if I did. Can you write a function that would do what you want?
Caution: Contents may have been coded under pressure.
| [reply] [d/l] [select] |
I didn't state my point well. What you appear to be suggesting is a special case of what given does: topicalize something so you can both test and reuse it.
And also return it. It seems to me that given would require an extra layer in the form another block around it. And it is a far general tool and to use it for this purpose would require to lose any conciseness and terseness that was being sought in the first place. What I'm thinking of is a specialized one, just less specialized than say C<||> or C<//>.
I say this notwithstanding that some time ago I mused on a similar (not identical) notion. It didn't generate much excitement, either.
Well, I ++'ed that, as well this, for sympathy. Actually I kinda liked the idea, but for the bare operators that really do not fit well both in 5 and 6.
Can you write a function that would do what you want?
I'm not really sure: you can certainly define operators, which is fun. In fact finally operators are nothing other than regular functions. My favourite example (basically, the only one I'm familiar with), which you can run in pugs already is:
pugs> sub postfix:<!> (Int $n) { [*] 1..$n }
undef
pugs> say $_! for ^5
1
1
2
6
24
undef
But I don't know if it will be possible to create shortcutting operators, as I also wrote in the root node. Well, Perl 6 is supposed to have macros, and perhaps it will be doable with them, but I don't know anything about macros myself. Or else, since it will eventually have a grammar modifiable at runtime, one may act on that. (Not really for the faint of heart I suppose.) | [reply] [d/l] [select] |