Moritz Lenz wrote: > Instead we should provide a very DWIMmy way to (lazily) create objects > that behave differently in different contexts.
That's precisely what the Contextual::Return module does for Perl 5. It's less than perfect in Perl 5, because it has to be implemented via runtime trickery, and hence is too slow. But that problem will disappear in Perl 6 (and perhaps eventually in Perl 5 too) as I'll be able to use macros to remove the runtime overheads. > Patrick pointed out that it can currently be done with > > return $value but role { method Bool { > $code_for_boolean_context_here } }; This is essentially what Contextual::Return does, only with a dwimmier syntax. > And if you propose to keep want(), how would you think it could work? The only thing C::R doesn't handle that want() does is determining the arity of a list context (i.e. how many elements are expected back). That information can be very handy for optimization. And, yes, C::R would already handle it if I could think of a clean interface that was implementable in Perl 5 without source filters. Damian