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" ;
|
drop "Fall-through in case" ;
|
||||||
|
|
||||||
M: slice-error summary
|
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" ;
|
M: bounds-error summary drop "Sequence index out of bounds" ;
|
||||||
|
|
||||||
|
|
|
@ -214,24 +214,19 @@ INSTANCE: reversed virtual-sequence
|
||||||
|
|
||||||
! A slice of another sequence.
|
! A slice of another sequence.
|
||||||
TUPLE: slice
|
TUPLE: slice
|
||||||
{ from read-only }
|
{ from integer read-only }
|
||||||
{ to read-only }
|
{ to integer read-only }
|
||||||
{ seq read-only } ;
|
{ seq read-only } ;
|
||||||
|
|
||||||
: collapse-slice ( m n slice -- m' n' seq )
|
: collapse-slice ( m n slice -- m' n' seq )
|
||||||
[ from>> ] [ seq>> ] bi [ [ + ] curry bi@ ] dip ; inline
|
[ from>> ] [ seq>> ] bi [ [ + ] curry bi@ ] dip ; inline
|
||||||
|
|
||||||
ERROR: slice-error from to seq reason ;
|
ERROR: slice-error from to seq ;
|
||||||
|
|
||||||
: check-slice-error ( from to seq ? string -- from to seq )
|
|
||||||
[ slice-error ] curry when ; inline
|
|
||||||
|
|
||||||
: check-slice ( from to seq -- from to seq )
|
: check-slice ( from to seq -- from to seq )
|
||||||
3dup
|
pick 0 < [ slice-error ] when
|
||||||
[ 2drop 0 < "start < 0" check-slice-error ]
|
2dup length > [ slice-error ] when
|
||||||
[ [ drop ] 2dip length > "end > sequence" check-slice-error ]
|
2over > [ slice-error ] when ; inline
|
||||||
[ drop > "start > end" check-slice-error ]
|
|
||||||
3tri ; inline
|
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue