Go and generic programming on reddit, also touches on D
Marco Leise
Marco.Leise at gmx.de
Tue Sep 20 06:24:16 PDT 2011
Am 19.09.2011, 19:08 Uhr, schrieb Steven Schveighoffer
<schveiguy at yahoo.com>:
> On Mon, 19 Sep 2011 12:00:46 -0400, Timon Gehr <timon.gehr at gmx.ch> wrote:
>
>> On 09/19/2011 05:52 PM, Steven Schveighoffer wrote:
>
>>>
>>> $ should denote the end point of the aggregate, but it does not have to
>>> be equivalent to length, or even an integer/uint. It should just mean
>>> "end".
>>
>> Point taken. What is the solution for infinite ranges? Should any
>> arithmetics on $ just be disallowed?
>
> I think $ should not pose any type restrictions, and whatever type you
> return can have whatever semantics you want. The only semantic
> restriction is it should mean "the end of the container".
>
> In other words, generic code that expects to be able to do:
>
> x[0..$/2]
>
> should only expect this to work when $ is a numeric value, or defines
> division by numbers.
>
> Technically, half of infinity is still infinity, so the type of $ could
> be defined so that any arithmetic operations on it result in itself ;)
>
> -Steve
The documentation of such generic code would make it obvious, that it
cannot work with infinite ranges.
sort() on a list of all primes for example is obviously not working.
Btw, I don't mind [^..$]. I think it is clear for everyone who ever wrote
a regex and easy for anyone else.
For natrually 0 based ranges, you'd still use 0. ^ would just be
obfuscating there.
More information about the Digitalmars-d
mailing list