Raku / old-design-docs

Raku language design documents
https://design.raku.org/
Artistic License 2.0
124 stars 36 forks source link

S03 is self-contradictory on unary hypers (recursive vs. flat) #42

Closed moritz closed 11 years ago

moritz commented 11 years ago

S03 says

Unary hyper operators always produce a hash or array of exactly the
same I<declared> shape as the single argument.  If the item is not
declared with a shape, only the top dimension is mapped, equivalent
to a normal C<.map> method.  

And later says

Hyper operators are defined recursively on nested arrays, so:

    -« [[1, 2], 3]               #    [-«[1, 2], -«3]
                                 # == [[-1, -2], -3]

which is in direct contradiction to the earlier statement. Which one is true?

pmichaud commented 11 years ago

The spec also has the following (from a commit that was apparently earlier than the snippet that moritz cites above)::

For unary hypers, we use a
policy called "duck mapping", which says that when a node responds
directly to the operator supplied, it is considered a leaf node,
and any Iterable components of the node are ignored.  If and only if
a node does not respond to the operator, it is examined to see if is
Iterable, and recursion occurs.

Pm