Hi,
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.
there're at least three different ways which do want you want:
# Using a closure
my $s = { "value t is $t" };
# And then
say $s(); # Note the ()
# Using Proxy
my $s := new Proxy: FETCH => { "value t is $t" };
# And then
say $s; # Note no ()
# With nothingmuch's lazy proposal (implemented in Pugs)
my $s := lazy { "value t is $t" };
say $s; # Again, no () needed
BTW, does Proxy fill in an appropriate default if one misses STORE? I.e.
new Proxy: FETCH => { "foo" }; # same as
new Proxy:
FETCH => { "foo" },
STORE => {
die "No STORE block...";
};
--Ingo
--
Linux, the choice of a GNU | The next statement is not true.
generation on a dual AMD | The previous statement is true.
Athlon! |