On Fri, Sep 03, 2004 at 07:42:53PM -0500, Rod Adams wrote:
: What jumps to my mind is that inside an array subscript could be 
: (sub)?context of it's own. Then one could do:
: 
: @ints[.beg .. .end ; .beg + 3 .. .end];

Awful dotty...

: Where the .beg and .end would relate to @ints.shape[0] or @ints.shape[1] 
: depending on which position it's in.
: 
: My only issue with this, and why I refered to it as a possible 
: subcontext, is that it's easy to concieve of somewanting to use the 
: prior context to generate the subscripts for an array.

That too...

: The other idea which jumps to mind was to create an operator which tell 
: the compiler to treat the the following number as if it referred to a 
: 0-based (sub)array, and negatives count off the end. What springs to my 
: mind is that we are saying this is the "relative to start / end" of the 
: range, so I will call it Δ (capital delta).
: 
: @ints[ Δ0 .. Δ-1 ; Δ3 .. Δ-1 ];
: 
: It at least looks nice.

I'd prefer to keep things in the Latin-1 range though.

Here's some other screwy ideas:

    @ints[A..Z]
    @ints[=+0..=-1]
    @ints[|+0..|-1]
    @ints[\+0..\-1]
    @ints[{0}..{-1}]

There's something to be said for the last one.  Those are actually
closures, so it'd be perfectly natural for the subscript to delay
evaluation of those numbers until it know the current bounds of the
current dimension.  The other syntaxes would have to be recognized
and translated to @ints.shape[$dim].beg and .end.  Which would
preclude them from being used outside a subscript:

    @allbutone = (A..Z-1);
    return @[EMAIL PROTECTED];

I suppose we could always get around that with special endpoint objects.
But closures are already special.  On the other hand, that's a real
minus in the closure, so it's sort of making the same mistake as Perl 5.

Though if we went with A and Z, I suppose for consistency the
corresponding methods would want to be:

    @ints.shape[$dim].A
    @ints.shape[$dim].Z

And that A..Z notation has the benefit of *not* relying on the -1 hack.
(Though presumably the \+ and \- style thingies are two-character
unary operators, not real numeric operators.  In which case \-0 means
the first unused entry after the array.  Poor-man's push:

    @ints[\-0] = $x;

Could even do the same chicanery with {+0} and {-1}, I suppose, but that
feels tacky.

I guess I still have a soft spot for the A to Z approach:

    @ints[Z+1] = $x;

I wonder if that means that @ints.shape[n].AZ returns a range.

The fun thing would be getting A..Z to work for enumerated ranges of
hash keys.  I thought it was kind of fun that Perl 5's restricted
hashes naturally fell out of shape("Foo", "Bar", "Baz").  I guess
that means the .. operator has to be sensitive to which subscript
it's being expanded in, though.  And A+1..Z-1 would presumably be
smart enough to give you only a "Bar"...which some folks might be
happy enough with.

Larry

Reply via email to