You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The recent-ish Perl 6 addition of the keywords with, orwith, without is (IMHO) a rare missed opportunity to abstract away a common solution to a set of related problems, and providing that common solution as a single thing, for example a single keyword.
Perhaps things could've looked differently if macros had been further progressed in Perl 6-land. I dunno.
Here I propose such an abstracted solution. 007 can try it out and see how it fits. The proposal adds the statement form definitely, with code that looks like this:
definitely if foo() -> value {
# ...
}
Which desugars to the following (⦃⦄ indicating hygiene):
if ⦃ my temp = foo(); temp != None && temp ⦄ -> value {
# ...
}
The form else definitely if should also work under this proposal. (Corresponding to Perl 6's orwith.)
There is no unless in 007 (corresponding to Perl 6's without), but if there ever were a serious one, I'd expect definitely unless to work out-of-the box by seamlessly composing with this macro. (But I might settle for a good explanation why that wouldn't work so easily, or be useless, or whatever. It sure seems that the block parameter of a definitely unless would be a lot less useful.) If it does work, I'd expect it to work through a conditional statement protocol somehow.
I'd expect definitely while to work along very similar principles. Ditto ditto definitely until, see above.
I wouldn't expect the definitely form to work with an (also macro-provided) ?? !! (see #163). Mostly since definitely would be a statement form, and ?? !! an operator.
The text was updated successfully, but these errors were encountered:
I think allowing where as part of the conditional would be more generally useful.
(I do realise that it seems awkward)
if foo() where .defined -> \value { # block would get run if `foo` returned `0`
# ...
}
if file-foo() where :e -> \filename {
# ...
}
I do think it is worthwhile to proceed with implementing definitely if as you stated.
As this is the sort of feature I would like to be able to easily create in the future.
@b2gills Both of your examples are already provided by grep.
if &{ False }().grep(*.defined) -> $x { say ~$x } # OUTPUT: 'False'
Some crazy people already floated the idea of aliasing grep as where but that idea got shot down 😄
@masak's suggestions seems more to do with replacing 3 new keywords with 1 qualifying keyword that can slot in front of already existing branching constructs. If that is a correct assessment, then I like the idea.
@masak's suggestions seems more to do with replacing 3 new keywords with 1 qualifying keyword that can slot in front of already existing branching constructs. If that is a correct assessment, then I like the idea.
That's right.
But see also #237, which is a solution in expression-land to a partially overlapping problem. 😄
The recent-ish Perl 6 addition of the keywords with, orwith, without is (IMHO) a rare missed opportunity to abstract away a common solution to a set of related problems, and providing that common solution as a single thing, for example a single keyword.
Perhaps things could've looked differently if macros had been further progressed in Perl 6-land. I dunno.
Here I propose such an abstracted solution. 007 can try it out and see how it fits. The proposal adds the statement form
definitely, with code that looks like this:Which desugars to the following (⦃⦄ indicating hygiene):
The form
else definitely ifshould also work under this proposal. (Corresponding to Perl 6'sorwith.)There is no
unlessin 007 (corresponding to Perl 6'swithout), but if there ever were a serious one, I'd expectdefinitely unlessto work out-of-the box by seamlessly composing with this macro. (But I might settle for a good explanation why that wouldn't work so easily, or be useless, or whatever. It sure seems that the block parameter of adefinitely unlesswould be a lot less useful.) If it does work, I'd expect it to work through a conditional statement protocol somehow.I'd expect
definitely whileto work along very similar principles. Ditto dittodefinitely until, see above.I wouldn't expect the
definitelyform to work with an (also macro-provided)?? !!(see #163). Mostly sincedefinitelywould be a statement form, and?? !!an operator.The text was updated successfully, but these errors were encountered: