My perspective from PDL is that "(1)[0][0][0]"..."[0]" should evaluate to 1. The artificial distinction between a scalar and an array of length 1 (in each dimension) is the source of endless hassles, and it's a pretty simple DWIM to allow indexing of element 0 of any unused dimension. That makes it much, much easier to write code that generalizes, because you don't have to check for the scalar case -- you can always assume that any given dimensional axis will always have one value along it (*), and loop/thread/whatever along that dimension.

(*) Of course, that's assuming that there's at least one value in the list as a whole -- PDL does, and perl 6 should, support zero-element lists; any looping or threading construct on a zero-element list is a no-op.

Jonathan Scott Duff wrote:

We're discussing the proper semantics of (1)[0] on #perl6. Here's
where we're at so far:

1. specialise ()[] to parse as (,)[]
2. scalars are singleton lists, so ()[] naturally
3. make (1)[0] die horribly.

We all seem to agree that #3 is least useful and probably wrong. But
there's a divide between whether #1 or #2 is the "right" behavior.

#2 implies that (1)[0][0][0][0] == 1
#1 means that (1)[0] == 1 and (1)[0][0] is an error

FWIW, I'm in favor of #1

What does p6l think?  (What does @Larry think?)

-Scott





Reply via email to