problem-solving icon indicating copy to clipboard operation
problem-solving copied to clipboard

Should duckmap work with code without explicit signatures?

Open doomvox opened this issue 6 months ago • 4 comments

The way duckmap works has varied with different versions of Raku. I used to think that the correct behavior was to try the indicated operation, and if it failed, pass through the original value, though the documentation only shows code examples that have explicit "where" tests that limit the operation to appropriate arguments.

Experimenting with duckmap, I note that while this works:

    <a b c 1 2 3>.duckmap(-> $_ where Numeric { $_ + 1 }).say;
    # OUTPUT: (a b c 2 3 4)

This doesn't work:

    <a b c 1 2 3>.duckmap({ $_ + 1 }).say;

Or at least it doesn't work with recent versions of Raku, I have seen it work with an older version from 2023, in which case it produces the same output as the first version. With a recent Raku build, it errors out:

 Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏a' (indicated by ⏏)

My question is was this change intentional? The second form would be very convenient if it continued to work, but then, I can also see how it might seem too irregular...

doomvox avatar Jul 17 '25 02:07 doomvox