May 17, 2010
bearophile Wrote:

> Kagamin:
> > half of a slice: a[None+len(a) : None]

I meant, Python is not a silver bullet and its abstraction of first and last indexes leaks (you like it, don't you?)
May 17, 2010
On 05/14/2010 08:20 AM, Steven Schveighoffer wrote:
> Currently, D supports the special symbol $ to mean the end of a
> container/range.
>
> However, there is no analogous symbol to mean "beginning of a
> container/range". For arrays, there is none necessary, 0 is always the
> first element. But not all containers are arrays.
>
> I'm running into a dilemma for dcollections, I have found a way to make
> all containers support fast slicing (basically by imposing some
> limitations), and I would like to support *both* beginning and end symbols.
>
> Currently, you can slice something in dcollections via:
>
> coll[coll.begin..coll.end];
>
>
> -Steve

Does your collections library allow for code like

coll[coll.begin + 1 .. coll.end]

?
May 17, 2010
On Mon, 17 May 2010 11:02:05 -0400, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:

> On 05/14/2010 08:20 AM, Steven Schveighoffer wrote:
>> Currently, D supports the special symbol $ to mean the end of a
>> container/range.
>>
>> However, there is no analogous symbol to mean "beginning of a
>> container/range". For arrays, there is none necessary, 0 is always the
>> first element. But not all containers are arrays.
>>
>> I'm running into a dilemma for dcollections, I have found a way to make
>> all containers support fast slicing (basically by imposing some
>> limitations), and I would like to support *both* beginning and end symbols.
>>
>> Currently, you can slice something in dcollections via:
>>
>> coll[coll.begin..coll.end];
>>
>>
>> -Steve
>
> Does your collections library allow for code like
>
> coll[coll.begin + 1 .. coll.end]

No.  begin and end return cursors, which are essentially non-movable pointers.

The only collection where adding an integer to a cursor would be feasible is ArrayList, which does support slicing via indexes (and indexes can be added/subtracted as needed).

Note, I'm not trying to make slicing dcollections as comprehensive as slicing with arrays, I'm just looking to avoid the verbosity of re-stating the container's symbol when specifying the beginning or end.  In all dcollections containers, one can always slice where one of the endpoints is begin or end.

I probably should at least add opDollar to ArrayList...

-Steve
May 17, 2010
On 05/17/2010 10:15 AM, Steven Schveighoffer wrote:
> On Mon, 17 May 2010 11:02:05 -0400, Ellery Newcomer
> <ellery-newcomer@utulsa.edu> wrote:
>>
>> Does your collections library allow for code like
>>
>> coll[coll.begin + 1 .. coll.end]
>
> No. begin and end return cursors, which are essentially non-movable
> pointers.
>
> The only collection where adding an integer to a cursor would be
> feasible is ArrayList, which does support slicing via indexes (and
> indexes can be added/subtracted as needed).
>

emphasis on the semantics (slice starting at second element), not the arithmetic, sorry.
1 2 3 4 5
Next ›   Last »