sequences: rename virtual-seq to virtual-exemplar

db4
Philipp Brüschweiler 2009-11-07 00:06:26 +01:00
parent c5c0e274cb
commit 8163c47b4a
11 changed files with 26 additions and 23 deletions

View File

@ -21,7 +21,7 @@ M: circular length seq>> length ;
M: circular virtual@ circular-wrap seq>> ;
M: circular virtual-seq seq>> ;
M: circular virtual-exemplar seq>> ;
: change-circular-start ( n circular -- )
#! change start to (start + n) mod length

View File

@ -8,7 +8,7 @@ TUPLE: column seq col ;
C: <column> column
M: column virtual-seq seq>> ;
M: column virtual-exemplar seq>> ;
M: column virtual@ [ col>> swap ] [ seq>> ] bi nth bounds-check ;
M: column length seq>> length ;

View File

@ -12,7 +12,7 @@ TUPLE: simple-cord
M: simple-cord length
[ first>> length ] [ second>> length ] bi + ; inline
M: simple-cord virtual-seq first>> ; inline
M: simple-cord virtual-exemplar first>> ; inline
M: simple-cord virtual@
2dup first>> length <
@ -28,7 +28,7 @@ M: multi-cord virtual@
seqs>> [ first <=> ] with search nip
[ first - ] [ second ] bi ; inline
M: multi-cord virtual-seq
M: multi-cord virtual-exemplar
seqs>> [ f ] [ first second ] if-empty ; inline
: <cord> ( seqs -- cord )

View File

@ -117,7 +117,7 @@ M: blas-vector-base equal?
M: blas-vector-base length
length>> ;
M: blas-vector-base virtual-seq
M: blas-vector-base virtual-exemplar
(blas-direct-array) ;
M: blas-vector-base virtual@
[ inc>> * ] [ nip (blas-direct-array) ] 2bi ;

View File

@ -17,3 +17,4 @@ IN: sequences.merged.tests
[ 4 ] [ 4 { 1 2 } { 3 4 } { 5 6 } 3merge nth ] unit-test
[ "" ] [ "abcdefg" "" 2merge ] unit-test
[ "a1b2" ] [ "abc" "12" <2merged> "" like ] unit-test

View File

@ -20,11 +20,12 @@ C: <merged> merged
[ <3merged> ] 3keep 2drop like ;
M: merged length
seqs>> [ [ length ] [ min ] map-reduce ] [ length ] bi * ;
seqs>> [ [ length ] [ min ] map-reduce ] [ length ] bi * ; inline
M: merged virtual@ ( n seq -- n' seq' )
seqs>> [ length /mod ] [ nth-unsafe ] bi ;
seqs>> [ length /mod ] [ nth-unsafe ] bi ; inline
M: merged virtual-seq ( merged -- seq ) [ ] { } map-as ;
M: merged virtual-exemplar ( merged -- seq )
seqs>> [ f ] [ first ] if-empty ; inline
INSTANCE: merged virtual-sequence

View File

@ -61,7 +61,7 @@ INSTANCE: curry immutable-sequence
M: compose length
[ first>> length ] [ second>> length ] bi + ;
M: compose virtual-seq first>> ;
M: compose virtual-exemplar first>> ;
M: compose virtual@
2dup first>> length < [

View File

@ -1175,17 +1175,17 @@ HELP: partition
}
} ;
HELP: virtual-seq
HELP: virtual-exemplar
{ $values
{ "seq" sequence }
{ "seq'" sequence } }
{ $description "Part of the virtual sequence protocol, this word is used to return an underlying array from which to look up a value at an index given by " { $link virtual@ } "." } ;
{ $description "Part of the virtual sequence protocol, this word is used to return an exemplar of the underlying storage. This is used in words like " { $link new-sequence } "." } ;
HELP: virtual@
{ $values
{ "n" integer } { "seq" sequence }
{ "n'" integer } { "seq'" sequence } }
{ $description "Part of the sequence protocol, this word translates the input index " { $snippet "n" } " into an index into the underlying storage returned by " { $link virtual-seq } "." } ;
{ $description "Part of the sequence protocol, this word translates the input index " { $snippet "n" } " into an index and the underlying storage this index points into." } ;
HELP: 2map-reduce
{ $values
@ -1397,9 +1397,9 @@ $nl
ARTICLE: "virtual-sequences-protocol" "Virtual sequence protocol"
"Virtual sequences must know their length:"
{ $subsections length }
"The underlying sequence to look up a value in:"
{ $subsections virtual-seq }
"The index of the value in the underlying sequence:"
"An exemplar of the underlying storage:"
{ $subsections virtual-exemplar }
"The index and the underlying storage where the value is located:"
{ $subsections virtual@ } ;
ARTICLE: "virtual-sequences" "Virtual sequences"

View File

@ -182,15 +182,15 @@ PRIVATE>
2dup bounds-check? [ nth-unsafe ] [ 2drop f ] if ; inline
MIXIN: virtual-sequence
GENERIC: virtual-seq ( seq -- seq' )
GENERIC: virtual-exemplar ( seq -- seq' )
GENERIC: virtual@ ( n seq -- n' seq' )
M: virtual-sequence nth virtual@ nth ; inline
M: virtual-sequence set-nth virtual@ set-nth ; inline
M: virtual-sequence nth-unsafe virtual@ nth-unsafe ; inline
M: virtual-sequence set-nth-unsafe virtual@ set-nth-unsafe ; inline
M: virtual-sequence like virtual-seq like ; inline
M: virtual-sequence new-sequence virtual-seq new-sequence ; inline
M: virtual-sequence like virtual-exemplar like ; inline
M: virtual-sequence new-sequence virtual-exemplar new-sequence ; inline
INSTANCE: virtual-sequence sequence
@ -199,7 +199,7 @@ TUPLE: reversed { seq read-only } ;
C: <reversed> reversed
M: reversed virtual-seq seq>> ; inline
M: reversed virtual-exemplar seq>> ; inline
M: reversed virtual@ seq>> [ length swap - 1 - ] keep ; inline
M: reversed length seq>> length ; inline
@ -231,7 +231,7 @@ TUPLE: slice-error from to seq reason ;
check-slice
slice boa ; inline
M: slice virtual-seq seq>> ; inline
M: slice virtual-exemplar seq>> ; inline
M: slice virtual@ [ from>> + ] [ seq>> ] bi ; inline

View File

@ -21,7 +21,7 @@ TUPLE: 1modified < modified seq ;
M: modified length seq>> length ;
M: modified set-length seq>> set-length ;
M: 1modified virtual-seq seq>> ;
M: 1modified virtual-exemplar seq>> ;
TUPLE: scaled < 1modified c ;
C: <scaled> scaled
@ -71,7 +71,8 @@ M: summed modified-set-nth ( elt n seq -- ) immutable ;
M: summed set-length ( n seq -- )
seqs>> [ set-length ] with each ;
M: summed virtual-seq ( summed -- seq ) [ ] { } map-as ;
M: summed virtual-exemplar ( summed -- seq )
seqs>> [ f ] [ first ] if-empty ;
: <2summed> ( seq seq -- summed-seq ) 2array <summed> ;
: <3summed> ( seq seq seq -- summed-seq ) 3array <summed> ;

View File

@ -16,6 +16,6 @@ M: repeating set-length (>>len) ;
M: repeating virtual@ ( n seq -- n' seq' ) circular>> ;
M: repeating virtual-seq circular>> ;
M: repeating virtual-exemplar circular>> ;
INSTANCE: repeating virtual-sequence