[C++-sig] GNU gettext and "_"

David Abrahams david.abrahams at rcn.com
Thu Jun 20 23:26:21 CEST 2002


----- Original Message -----
From: "Pearu Peterson" <pearu at cens.ioc.ee>

> > see ceval.c: apply_slice()/assign_slice()
>
> I am looking at Objects/sliceobject.c and the docs of api/slice-objects.

Well apparently the latest CVS fixes it for lists and tuples, but AFAICT
not for older extension types which don't implement the mapping protocol.

> > So, really, I'm not kidding: None is not a substitute for () where
slicing
> > is concerned.
>
> Me neither. I guess we are talking about different things: me about
> using slice objects for getting slices while you about getting slices
> directly (which I think would mean that you'll need to repeat some of the
> code from Python sources that could be avoided when using slice objects).

No, I don't think we're discussing different things.

> The slice constructor accepts any objects as arguments and when slice
> object is used to calculate indices then None is used to indicate missing
> values in
>   start:stop:step
> pattern (see sliceobject.c). On the other hand, when getting slices of

Yes, thanks, I know this stuff.

> sequences, only integer arguments are accepted (see the signatures of
> Py(Tuple|List)_GetSlice functions).

I know that too.

> I was assuming that
>   x.slice(...)
> method first constructs a slice object.

I could make it do that, but...

> This slice object is used to
> calculate the indices that in turn are used to construct the slice of x.

I would have to look at the target object to see if it as an mp_getitem
field, then if it doesn't I would have to try to translate None to an int
zero... and who knows what else?

> If this is not what you expect x.slice(...) to do, then I am confused.

I expect x.slice(_,y) to be equivalent to x[:y] in Python. Period. How we
get there is (mostly) immaterial. However, using slice objects doesn't
appear to be a universal solution, at least not in current Pythons.

> Notice that (probably for efficiency reasons) list and tuple objects do
> not use slice objects at all. Nor they accept the step argument.

Thanks, I'm aware of that, too.

> So, what is the actual purpose of x.slice(start,stop,step)? Is x always
> assumed to be a standard Python sequence like list or tuple?

No

> Or can x be
> also user defined object like Numeric array that accepts also step
> argument through the slice object feature?

Yes.

-Dave







More information about the Cplusplus-sig mailing list