On Tue, Aug 23, 2005 at 10:56:08 -0700, Larry Wall wrote: > We could probably extend "is cached" to attributes (and their implied > accessors) if lazy blocks aren't sufficient.
Hmm... With the whole distinction of &foo as a value and &foo() as a application of the value, maybe we can sometimes assign a sub as an rvalue by making a "weak" call. sub lazy (Code &f) { return &f.weak_call; } I like the relation to is cached, but I think it might be incorrect, if the lazy block is reused. BTW, I'm the "nothingmuch" who initially lobbied for lazy { }... =) > : sub &infix:<||> ($left, $right is delayed) { > : $left ?? $left :: ** $right; # can you steamroll a scalar? > : } > > I'd really like to discourage people from writing thunks without curlies. Then how do we define &infix:<||>'s prototype? > I don't think steamrollering a scalar works--it would just take it > as an operation on a list rather than on the elements of the list. > You can't really delazify until you know what kind of a scalar you > want, I suspect, because the lazy closure itself might need to know > in what context to run. Otherwise you just have to return a proxy > object that might turn into a string or number or int or whatever > value is eventually wanted. Of course, presumably infix:<||> has > that context already, so maybe we're looking for something like > > $right.want This makes sense, but shuts off the 'want' behavior. I think we should have an implicit $?CONTEXT object in each sub, and then you can say to it $?CONTEXT.unwrap($right); or something along that metaphor. This is also nice for things like method moose (...) { my Container $x = $?CONTEXT.eval( $?SELF.SUPER::moose ); # maybe even a bit like Sub::Uplevel ... # you can look inside $x now, but you can't "damage" it # anymore ... $x.unwrap; # this serves as context passthrough } > to force value-finding behavior iff it's called for. After all, you > probably want it to stay lazy if you call it in undifferentiated scalar > context: > > $x = $y || lazy { z() } Yes, I didn't think about that... This is lazyness stacking though, I think. -- () Yuval Kogman <[EMAIL PROTECTED]> 0xEBD27418 perl hacker & /\ kung foo master: /methinks long and hard, and runs away: neeyah!!!
pgpxtNeHzOOee.pgp
Description: PGP signature