opSlice and $

Witold Baryluk baryluk at smp.if.uj.edu.pl
Wed Sep 12 04:08:30 PDT 2007


Dnia Tue, 11 Sep 2007 16:16:58 -0400
S. <S at s.com> napisał/a:


> 
> Multidimensional slicing isn't mentioned in the language spec.  When
> was this added?
Never. yet.

> 
> I would rather see $ be an alias for int.max for overloaded
> operators.  This should be included in the spec, and then it is up to
> the overloaded operator to handle this to mean the last item. (either
> that or there could be another type added for indexes that includes
> this concept as a special bit sequence)

Good, idea, but what about $-1, or $-100000000, it will not be
easy to distinguish this from normal numbers.

Things like c[1 .. $/2] are correct.

Problem is also with other types, like strings.

c["a" .. $-4].

Is $ some special value, some special symbol, or index of last item (or
beyond last item)?

Imho this should be a choice of user via some operator overloading.
like
char[] opDollar()

but there will be problem with (hypothetical) multidimensional slices.
(and also multidimensional arrays).

c[1..$,2..$]   each of dollar means something different

c[$/2,$/3].   similary.



mayby

type1 opDollar_1()
type2 opDollar_2()


but not always second dollar is independend of first.


for example

let c be kind od triangular array, then $ here will be like
second index in first subslice.

c[1..4, 1..$]          // $ == 4
c[1..5, 1..$]          // $ == 5



Creating temporary objects are very very genneral for such
constructions, but anyway we will need opDollar.


-- 
Witold Baryluk, aleph0
MAIL: baryluk at smp.if.uj.edu.pl
JID: movax at jabber.autocom.pl



More information about the Digitalmars-d mailing list