[PD] RFC: "list split" abstraction for negative indices

Mathieu Bouchard matju at artengine.ca
Wed Nov 2 10:42:35 CET 2005

On Wed, 2 Nov 2005, Frank Barknecht wrote:

> I want to include an abstraction into [list]-abs which acts as a wrapper
> around [list split] but also accepts negative indices to split off a
> list from the back. That is, a "list 0 1 2 3 4" splitted at index "-2"
> would give two lists, "0 1 2" and "3 4".

Negative indices have a precedent in both Ruby and Python. Also, many
GridFlow objects support such a thing.

> To recapitulate: Currently the standard [list split 2] would send "0 1"
> to the first outlet and "2 3 4" to the second.  Should a fictional [list
> split -2] send "3 4" to the first or to the second outlet?

There is no precedent of something sufficiently like [list split] in Ruby, 
maybe Array#slice! would be the closest, which has in input a list and a 
cut-point just like yours, but also an optional length, defaulting to 1.
Then it returns the specified portion of the list, and deletes that very 
same portion from the original list. For example:

a = [0 1 2 3 4]
p a.slice!(2,2)      # shows [2,3]
p a                  # shows [0,1,4]

I don't know which of those two outputs should be the main one, but it 
should mirror a subsequent "unsplit" or "unslice" so that e.g.:

[list slice   2 2]
 |              |
[list unslice 2 2]

is a no-op (rebuilds exactly the same list), if the list is long enough 
and if the starting position is nonnegative.

> (Note: I tend to prefer sendign "3 4"  to the first outlet, as it's
> technically easier, 

I don't know. What's technically easier about it?

Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju
Freelance Digital Arts Engineer, Montréal QC Canada

More information about the Pd-list mailing list