before method foo …
etc style code, method
is no longer a keyword, but part of the identifier or ‘place’, analogous to setf
in lisps.
If you’re going to redo before/after/around, then I have a sneaking regard for lisp style named advice, so
before method foo () { … }
could become:
wrapper massage_args :around (…) {…}
wrap method foo :with(massage_args);
Also, if we’re borrowing from Lisp, then before/after/around could (should?) be joined by before-while
(if the advice returns false, don’t call the advised function), before-until
(only call the advised function if the advice returns false), override
(simply replace the advised function), filter-args
and filter-return
(massage the arguments or return value).
Yes, all of these extra modifier types can be implemented in terms of around, but I’d suggest that being able to more finely define up front what a piece of advice is going to do will help make things slightly easier to reason about.
]]>sub tails(Iterable \s) { s, *.skip(1) ...^ !* } my \strong = tails(^Inf .grep: &is-prime) \ .map({ $_.head(3) }) \ .map(-> (\pre, \p, \post) { ( p, (pre + post)/2 ) }) \ .grep(-> (\p, \target) { p > target } ) \ .map: *[0]
I'm sure there's a neater way of expressing the basic idea (.map({$_.head(3)})
seems like it could be eliminated with a better destructuring signature on the next line, for instance), but I'm nowhere near fluent in Perl 6 yet and I couldn't work out how to do it.