sequences: integer slots in slice, don't store reason in slice-error.
parent
242d18d95e
commit
94cddbe927
|
@ -235,7 +235,12 @@ M: no-case summary
|
|||
drop "Fall-through in case" ;
|
||||
|
||||
M: slice-error summary
|
||||
drop "Cannot create slice" ;
|
||||
"Cannot create slice" swap {
|
||||
{ [ dup from>> 0 < ] [ ": from < 0" ] }
|
||||
{ [ dup [ to>> ] [ seq>> length ] bi > ] [ ": to > length" ] }
|
||||
{ [ dup [ from>> ] [ to>> ] bi > ] [ ": from > to" ] }
|
||||
[ f ]
|
||||
} cond nip append ;
|
||||
|
||||
M: bounds-error summary drop "Sequence index out of bounds" ;
|
||||
|
||||
|
|
|
@ -214,24 +214,19 @@ INSTANCE: reversed virtual-sequence
|
|||
|
||||
! A slice of another sequence.
|
||||
TUPLE: slice
|
||||
{ from read-only }
|
||||
{ to read-only }
|
||||
{ seq read-only } ;
|
||||
{ from integer read-only }
|
||||
{ to integer read-only }
|
||||
{ seq read-only } ;
|
||||
|
||||
: collapse-slice ( m n slice -- m' n' seq )
|
||||
[ from>> ] [ seq>> ] bi [ [ + ] curry bi@ ] dip ; inline
|
||||
|
||||
ERROR: slice-error from to seq reason ;
|
||||
|
||||
: check-slice-error ( from to seq ? string -- from to seq )
|
||||
[ slice-error ] curry when ; inline
|
||||
ERROR: slice-error from to seq ;
|
||||
|
||||
: check-slice ( from to seq -- from to seq )
|
||||
3dup
|
||||
[ 2drop 0 < "start < 0" check-slice-error ]
|
||||
[ [ drop ] 2dip length > "end > sequence" check-slice-error ]
|
||||
[ drop > "start > end" check-slice-error ]
|
||||
3tri ; inline
|
||||
pick 0 < [ slice-error ] when
|
||||
2dup length > [ slice-error ] when
|
||||
2over > [ slice-error ] when ; inline
|
||||
|
||||
<PRIVATE
|
||||
|
||||
|
|
Loading…
Reference in New Issue