[Submission] D Slices

eles eles at eles.com
Tue May 31 07:43:22 PDT 2011


Without being rude, but I find that you are too much a zealot and too
little of a listener. You are firing bullets in many, but wrong
directions, trying to scary and to impress.

Yes, I have no much experience with D, although I have some with C.
The syntax is not for D, but for general pseudo-code whose purpose
was to convey the idea, and not to inflame spirits about narrow
bracketing issues. The matter was not if a semicolon, or a bracket
for that matter, is appropriate or no.

In the same manner, you would try to shout down the relativity theory
for... improper English spelling (not to say that I am a second
Einstein...) because the author was... of German origin.

Although I disagree with Andrei's p.o.v. concerning exclusive right
limit, I much more appreciate his style to reply. Probably it is
because being so great, he feels no compulsive need to emphasize his
stature w.r.t. those that are littler than him. And he folloows and
fights the idea, maybe because he was able to overlook the
insignificant bracketing issues for something more important. But,
probably, his attitude is the attribute of great minds, not of the
littlest ones.

There is a saying... saying "you do not see the forest because of the
trees".

My apologies (to the others) for this little... bullet.


== Quote from Timon Gehr (timon.gehr at gmx.ch)'s article
> eles wrote:
> >> The right boundary of a slice is exclusive.
> >
> > I think it should be stated more obvious in the paper.
> >
> >> This makes sense, so you can
> >> do stuff like a[1..$] (== a[1..a.length]) to get a slice that
> > contains
> >> all elements of a except for the first one (a[0]).
> >
> > I disagree, but I have not much influence here, although I will
> > defend my point of view. I find it quite unpleasant to remember
which
> > of the left and right bounds are exclusive and, moreover, this
> No. I have never met half-open intervals that are open on the left
side. All you
> have to remember is that the interval is half-open.
> > precludes slicing with a[i1..i2] where i1 and i2 are only known at
> > the runtime and may be i2<i1 (and not necessarily i1<i2).
> It is always an error to slice a[i1..i2] with i2<i1. It is a flaw
in your code if
> you do not know that i1<i2. You can make this sure even if you do
not know the
> exact bounds.
> >
> > You will be forced to do smthng like:
> >
> > if(i1>i2)
> >  b=a[i1..i2]
> > else
> >  b=a[i2..i1]
> > end
> More semicolons and curly brackets and less "end" please. =)
> Your code as is (and if it compiled), will throw an exception in
debug or safe
> mode if i1!=i2. You understand that?
> I also do not get what point you are trying to sell with this
snippet, can you
> explain what you want to do with i2<i1?
> >
> > and is easy to forget (several lines below) if a[i1] or a[i2]
still
> > belongs to the slice or no.
> You can always do a[i1..i2+1] to get inclusive slicing.
> >
> > For example, it would be marvellous to implement definite integral
> > convention as: int(a,i1,i2)=sign(i1-i2)*sum(a[i1..i2]) w.r.t. the
> > mathematical convention.
> int is a keyword.
> >
> > For me, the right solution would have been to consider the
selection a
> > [0..$-1] to select all the elements of the array. This way, "$"
still
> > means "the length" and one has a clear view of the selection going
> > from a[0] to a["length"-1] as expected by someone used to 0-based
> > indexes. The slicing would be always inclusive, which is a matter
of
> > consistence (and goes in line with Walter speaking about the car
> > battery). Why to break this convention?
> >
> > If it is wrong, design it to appear being wrong.
> It is not wrong, but the right thing to do. I suspect you have not
done much
> coding (in D) given your code examples.
> half-open is the best choice for representing intervals wherever it
is possible.
> It reduces the amount of +-1 bugs in your code considerably. (try
it)
> Timon



More information about the Digitalmars-d mailing list