[Submission] D Slices

Timon Gehr timon.gehr at gmx.ch
Tue May 31 08:28:31 PDT 2011


eles wrote:
> 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.

Oh, sorry. I did not want to be rude.
Communicating over newsgroups tends to be working poorly in that respect.

>
> 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.

I agree syntax is not very important for that matter. It was not to be taken too
seriously; it was a joke, annotated by ":)".
But reviewing my post I can understand how it might have offended you. Sorry for that.
If somebody codes very much in a language, his pseudo-code tends to look much like
that language.
That's were I inferred that you do not have much experience with the way things
work in D.
Yet you seemed quite certain that D was doing it all wrong.
Try D some time. It is great.

>
> 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.

I think you are concentrating too much on my comments about syntax.
Fun fact: Most physicists did shout down the relativity theory in the beginning.
There was even a book titled "100 authors against Einstein." or similar.
Einstein did receive the Nobel prize, not for papers on relativity theory but for
his discovery of the photoelectric effect.
Today, most people will say relativity theory when they hear Einstein. So if you
have a really good point, please share. I agree that I have to get better at that.

And I was not disagreeing with your point of view because of syntactic issues, but
most likely because I have other use cases in mind than you. Again, what exactly
do you want to do with array slices?

There are perfectly valid uses of the slicing semantics you suggest, but I think
they are not a good fit for built-in D arrays.

>
> 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.

Yes, his answer was indeed quite political. Also, his English is better than mine.
I have no need to "emphasize my stature", I am trying to give arguments for what I
consider correct.

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

Please explain how it applies to me. True, I did not understand what you were
trying to do in your code snippet. That is why I asked.

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

I hope you wont conceive this message in a similar way.

Timon

>
>
> == 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