Virtual Slicing

Bryan Olson fakeaddress at nowhere.org
Mon Aug 29 21:55:20 CEST 2005


Sybren Stuvel wrote:
 > Bryan Olson enlightened us with:
 >
 >>I recently wrote a module supporting value-shared slicing.
 >
 > Maybe I'm dumb, but could you explain this concept? Why would someone
 > whant this?

My original motivation was reduce the amount of copying in some
tools that parse nested structures. All I really needed at the
time was a reference to a string, and the start and stop values.
Once I adopted Python's sequence interface, I thought I might as
well implement it consistently, generally, and completely.

So the first reason someone might want this is for efficiency,
in space and/or time.

The second reason is more abstract. Python's slice assignment is
a useful feature, but the slice selection must appear on the
right-hand-side of assignment. VSlice lets one instantiate the
updatable slice as an object, and pass it around.

I looked into supporting slice assignment between slices of
different sizes when possible, but the various options I came up
with all sucked.


-- 
--Bryan



More information about the Python-list mailing list