Here's what I found in S32:
deepmap
multi method deepmap ( @values: Code *&expression --> Any )
multi deepmap ( Code $expression, *@values --> Any )
Like map and duckmap, deepmap evaluates the expression for each of the
values you give it. Unlike map and duckmap, an element is considered a value
only if it does not do the Iterable role. If the element is iterable, the
algorithm recurses to produce an identical structure to its input. Elements
that are not iterable are considered leaf values and mapped through the
supplied expression.
Because deepmap is defined as a recursive implicit loop, loop controls
apply only to the current level of the tree.
/dogbert17
-----Original Message-----
From: Zoffix Znet via RT [mailto:[email protected]]
Sent: den 23 september 2016 18:39
To: [email protected]
Subject: [perl #129321] [BUG] deepmap can recurse indefinitely under some
circumstances
On Tue Sep 20 13:54:33 2016, [email protected] wrote:
> # tested with
>
> dogbert@dogbert-VirtualBox ~ $ perl6 -v This is Rakudo version
> 2016.09-19-g8be36b1 built on MoarVM version 2016.09 implementing Perl
> 6.c
>
> # the following two examples behave quite differently
>
> dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],4]; dd
> @a.duckmap({ $_ ~~ Int ?? $_ !! Any })' # this works as expected
> (1, (2, 3), 4)
>
> dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],"a"]; dd
> @a.duckmap({ $_ ~~ Int ?? $_ !! Any })' # this will hang or return
> 'Memory allocation failed; could not allocate xxxxxx bytes'
>
> /dogbert17
>
I see why the issue occurs, but have no idea what the correct behaviour should
be.
The docs for .duckmap read "For undefined return values, duckmap will try to
descend into the element if that element implements Iterable." but when would
an undefined Iterable would ever be descendable?
The hang itself happens here:
https://github.com/rakudo/rakudo/blob/e12ebb9/src/core/metaops.pm#L685
The Any returned from your condition is undefined, so duckmap calls the block
with it again, resulting in an infiniloop.
Based on the docs, a check for an Iterable is missing, but it feels wrong to me
that we'd be attempting to "descend" into an undefined Iterable :S