Here's what I think.
copyFrom: start to: stop
�� " ANSI Smalltalk section 5.7.8.7, reorganised a bit.
�� �� Answer a new collection containing all of the elements of the
�� �� receiver between the indices start and stop inclusive in their
�� �� original order.�� The element at index start in the receiver is
�� �� at index 1 in the result, the element at index start+1 is at
�� �� index 2, etc.�� If stop < start, the new collection is emptyy.
�� �� Otherwise, the size of the new collection is the maximum of
�� �� (stop - start + 1) and 0.�� The parameters start and stop must
�� �� be positive integers.
�� �� Errors
�� �� If stop >= start and (start < 1 or start > the receiver's size).
�� �� If stop >= start and (stop < 1 or stop > the receiver's size).
�� "
�� �� ((start isKindOf: Integer) and: [start positive])
�� �� �� ifFalse: [start error: 'not a positive integer'].
�� �� ((stop ��isKindOf: Integer) and: [stop ��positive])
�� �� �� ifFalse: [stop ��error: 'not a positive integer'].
�� �� ^stop < start
�� �� �� ��ifTrue: ��[self copyEmpty]
�� �� ��ifFalse: [(start between: 1 and: self size)
�� �� �� �� �� �� �� �� �� ��ifFalse: [start error: 'index out of range'].
�� �� �� �� �� �� �� �� ��(stop ��between: 1 and: self size)
�� �� �� �� �� �� �� �� �� ��ifFalse: [stop ��error: 'index out of range'].
�� �� �� �� �� �� �� �� ��self from: start to: stop collect: [:each | each]]
allButFirst
�� �� ^self allButFirst: 1
allButFirst: count
�� �� ^self copyFrom: count + 1 to: self size
allButLast
�� �� ^self allButLast: 1
allButLast: count
�� �� ^self copyFrom: 1 to: self size - count
first: count
�� �� "(x first: n) , (x allButFirst: n) = x and: [(x first: n) size = n]"
�� �� ^self copyFrom: 1 to: count
last: count
�� �� "(x allButLast: n) , (x last: n) = x and: [(x last: n) size = n]"
�� �� ^self copyFrom: self size - count to: self size
See the comments in #first: and #last: ?
In order to program effectively, I need operations with *simple* specifications.
"seq first: n�� returns the first n elements of seq or it's an error"
"seq last: n�� ��returns the last�� n elements of seq or it's an error"
This has the virtue of making these pretty redundant operations fully
consistent with #copyFrom:to: