C
Charles Comstock
I find myself frequently using array slice of 1..-1, to pass the rest of an
array onto something. While this is a reasonably concise syntax it is not the
most readable. I was curious if there had ever been interest in a rest operator
on an array?
For example
a = [1,2,3,4]
a[1..-1] # -> [2,3,4]
a.rest # -> [2,3,4]
I realize this might cause a few people to write programs in a more list
processing stance, for which the current arrays are probably not best suited.
However, the majority of the times I use this operator is for say reading in a
command as a the first arg, and passing the rest of the elements as the
parameters, and thus it would not be a performance issue. Rest should also have
the same copy symantics as the 1..-1 slice.
Any particular objections to this? Should I make this an RCR?
Charles Comstock
array onto something. While this is a reasonably concise syntax it is not the
most readable. I was curious if there had ever been interest in a rest operator
on an array?
For example
a = [1,2,3,4]
a[1..-1] # -> [2,3,4]
a.rest # -> [2,3,4]
I realize this might cause a few people to write programs in a more list
processing stance, for which the current arrays are probably not best suited.
However, the majority of the times I use this operator is for say reading in a
command as a the first arg, and passing the rest of the elements as the
parameters, and thus it would not be a performance issue. Rest should also have
the same copy symantics as the 1..-1 slice.
Any particular objections to this? Should I make this an RCR?
Charles Comstock