Go and generic programming on reddit, also touches on D

Steven Schveighoffer schveiguy at yahoo.com
Mon Sep 19 10:08:41 PDT 2011


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


More information about the Digitalmars-d mailing list