Front page | perl.perl6.language |
Postings from October 2014
state and = vs :=
Thread Next
From:
Father Chrysostomos
Date:
October 2, 2014 13:14
Subject:
state and = vs :=
Message ID:
6569C97C-DD78-4E0D-BA84-ACD82C70D80F@cpan.org
Does ‘state’ govern ‘:=’ the way it governs ‘=’? In other words, just as this:
state $x = 1;
only assigns to $x once (per closure), does the same apply to this?
state $x := $y;
I can’t find anything in the specs that implies that it does.
The reason I ask is that I am currently implementing binding for Perl 5, but the syntax is different—
\$x = \$y;
(The reason for the different syntax is that, when we tried to use :=, we could not find a coherent way to handle edge cases [e.g., flattening vs not flattening]. Reusing existing Perl 5 syntax seemed the most straightforward and intuitive approach.)
—and I am debating whether \state $x = \$y should bind only once or every time the surrounding code is executed. I could argue it either way (though I am leaning toward the latter), so I thought to find out what Perl 6 does.
Thread Next
-
state and = vs :=
by Father Chrysostomos