New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
duckmap can recurse indefinitely under some circumstances #5686
Comments
From @dogbert17# tested with dogbert@dogbert-VirtualBox ~ $ perl6 -v # the following two examples behave quite differently dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],4]; dd dogbert@dogbert-VirtualBox ~ $ perl6 -e 'my @a = [1,[2,3],"a"]; dd /dogbert17 |
From @zoffixznetOn Tue Sep 20 13:54:33 2016, jan-olof.hendig@bredband.net wrote:
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 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 |
The RT System itself - Status changed from 'new' to 'open' |
From @dogbert17Here's what I found in S32: deepmap multi method deepmap ( @values: Code *&expression --> 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----- On Tue Sep 20 13:54:33 2016, jan-olof.hendig@bredband.net wrote:
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 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 |
From @smls
"Try to descend" probably means that it should call .list on the element to remove any Scalar container, and then iterate over it like any other `map` or `for` loop. But I agree that it is not clear if the case of an undefined Iterable was considered by the authors of that design doc. There would be three possible ways to handle such an element: 1) Simply allow `.list` to treat it as a list of one element, which may be technically the most consistent behavior but also gives the most weird/unexpected result: ➜ say List.list.map({ $_ }).perl; 2) Throw an error, like a normal top-level `map` would: ➜ say List.map({ $_ }).perl; 3) Treat them as non-iterables, which would be another special case but possibly the most DWIM: ➜ say List.perl |
From @zoffixznetTests added in Raku/roast@ce3050e |
@zoffixznet - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#129321 (status was 'resolved')
Searchable as RT129321$
The text was updated successfully, but these errors were encountered: