Ahhhhh !!!
I had read about lazy and eager, but not appreciated what effect it
might have.
So the answer for my Tarjan module, which assumes a static network, is
to replace '.sort' with '.eager' .
However, ... the point at which I was getting an error in the modules
was the following code
my $wn = %!nodes{$w};
with $wn.index {
The error message was about accessing attributes in object at the 'with'
statement. Each value of %$node is a "Algorithm::Tarjan::Node" object
with an attribute .index. However, even though $wn had type
'Algorithm::Tarjan::Node', it had no attributes at all. So
say $wn.perl;
printed 'Algorithm::Tarjan::Node', but no attributes. Hence even a test
for definiteness blows up.
Given that I do not know much about lazy processing, I don't know if
this is a bug or expected behaviour.
Assuming it is expected behaviour:
$w is always a valid key, and so %!nodes{$w} should (eventually) have a
value. (If evaluated in an eager manner, then the program correctly
initialises all the values).
Suppose this is a part of a routine that can be called in a lazy manner,
what might be an idiomatic perl6 way to ensure that a valid value with
attributes is available for testing?
On Thursday, May 25, 2017 12:45 AM, Timo Paulssen wrote:
Have you considered the effects of lazy evaluation for the hash's values
method? .sort will eagerly evaluate the whole .values list (i.e.
snapshot it) while iterating over it will include added keys and such.