On Mon, Aug 22, 2005 at 13:25:57 -0700, Larry Wall wrote:
> On Tue, Aug 23, 2005 at 04:09:29AM +0800, Yiyi Hu wrote:
> : my( $s, $t ); $s = "value t is $t"; $t = "xyz"; print $s;
> : in perl 5, it will give a warning, and won't do "right" thing.
> : we have to use other way or eval '$s' before print to get a "correct"
> answer.
> :
> : So I wonder, If we can make $scalar lazy also. As array now is lazy by
> default.
> :
> : Even if making scalar lazy might cause problem sometimes, Is it
> : possible to add a property which is like
> : my $var is lazy; to handle these situation?
>
> In Perl 6 you make lazy scalars by putting curlies around them:
>
> my( $s, $t ); $s = { "value t is $t" }; $t = "xyz"; print $s();
>
> Currently we also require the de-lazifying context to supply a
> postfix .() marker, but possibly that could be assumed in a string
> or numeric context.
>
> I really don't see much benefit in making it easier than that.
I see one:
class Object {
has $.expensive_to_compute_but_cachable = delay {
...
};
}
OR
class Object {
has $.expensive_to_compute_but_cachable is delayed =
...;
}
And no one has to know that it's lazy.
With explicit code refs, you need to make an accessor:
class Object {
has $.expensive_to_compute_but_cachable;
method expensive_to_compute_but_cachable (
$.expensive_to_compute_but_cachable # i forget
how
# autrijus's "returned" attr on params works
) {
$.expensive_to_compute_but_cachable //= ...;
}
}
Which is just as much headache that we had to do in perl 5.
Also, lazifying semantics are consistent with
sub &infix:<||> ($left, $right is delayed) {
$left ?? $left :: ** $right; # can you steamroll a scalar?
}
--
() Yuval Kogman <[EMAIL PROTECTED]> 0xEBD27418 perl hacker &
/\ kung foo master: /me spreads pj3Ar using 0wnage: neeyah!!!!!!!!!!!
pgpqbfguyPqSX.pgp
Description: PGP signature
