Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
December 10, 2010 rationale: [] and () | ||||
---|---|---|---|---|
| ||||
What is the rationale for having both: normal and square brackets? I ask because in plain old C I interpreted the lexical difference of funtion calls and accesses to elements of arrays as a permanent hint for linear runtime in case of arrays. But because of `opIndex' this assumption has been invalidated a long time ago. -manfred |
December 10, 2010 Re: rationale: [] and () | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred_Nowak | Manfred_Nowak <svv1999@hotmail.com> wrote: > What is the rationale for having both: normal and square brackets? Mostly that C has both. Changing this would make the language feel rather more different from C/C++ than it already does. It is also syntactic sugar for element lookup. Rather than having to write some function name (that may or may not be the same for all collections), you can use []. > I ask because in plain old C I interpreted the lexical difference of > funtion calls and accesses to elements of arrays as a permanent hint for > linear runtime in case of arrays. > > But because of `opIndex' this assumption has been invalidated a long > time ago. No it hasn't. opIndex should still be O(1), it just can't be enforced. -- Simen |
December 10, 2010 Re: rationale: [] and () | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen kjaeraas | On Fri, 10 Dec 2010 09:42:51 -0500, Simen kjaeraas <simen.kjaras@gmail.com> wrote: > Manfred_Nowak <svv1999@hotmail.com> wrote: >> But because of `opIndex' this assumption has been invalidated a long >> time ago. > > No it hasn't. opIndex should still be O(1), it just can't be enforced. > er.. make that O(lg(n)) :) Essentially sub-linear. -Steve |
December 10, 2010 Re: rationale: [] and () | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer <schveiguy@yahoo.com> wrote: > On Fri, 10 Dec 2010 09:42:51 -0500, Simen kjaeraas <simen.kjaras@gmail.com> wrote: > >> Manfred_Nowak <svv1999@hotmail.com> wrote: > >>> But because of `opIndex' this assumption has been invalidated a long >>> time ago. >> >> No it hasn't. opIndex should still be O(1), it just can't be enforced. >> > > er.. make that O(lg(n)) :) Essentially sub-linear. Ah, yes. Sorry. -- Simen |
December 10, 2010 Re: rationale: [] and () | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer wrote:
> Essentially sub-linear.
... and I meant "_constant_ runtime in case of arrays".
BTW: did you notice, that the modell assumption of an access time independent from the total length of a used slice of memory seems to become wrong?
-manfred
|
Copyright © 1999-2021 by the D Language Foundation