Some cleanup

db4
Slava Pestov 2008-07-01 20:19:03 -05:00
parent f8fd065fc5
commit eb6a1de4a1
11 changed files with 19 additions and 73 deletions

View File

@ -11,7 +11,7 @@ IN: arrays.tests
[ V{ "a" "b" "c" } ] [ { "a" "b" "c" } >vector ] unit-test
[ f ] [ { "a" "b" "c" } dup >array eq? ] unit-test
[ t ] [ { "a" "b" "c" } dup { } like eq? ] unit-test
[ t ] [ { "a" "b" "c" } dup dup length array>vector underlying>> eq? ] unit-test
[ t ] [ { "a" "b" "c" } dup dup length vector boa underlying>> eq? ] unit-test
[ V{ "a" "b" "c" } ] [ { "a" "b" "c" } V{ } like ] unit-test
[ { "a" "b" "c" } ] [ { "a" } { "b" "c" } append ] unit-test
[ { "a" "b" "c" "d" "e" } ]

View File

@ -30,11 +30,6 @@ HELP: >byte-vector
{ $description "Outputs a freshly-allocated byte vector with the same elements as a given sequence." }
{ $errors "Throws an error if the sequence contains elements other than integers." } ;
HELP: byte-array>vector
{ $values { "byte-array" "an array" } { "length" "a non-negative integer" } { "byte-vector" byte-vector } }
{ $description "Creates a new byte vector using the array for underlying storage with the specified initial length." }
{ $warning "This word is in the " { $vocab-link "byte-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >byte-vector } " instead." } ;
HELP: BV{
{ $syntax "BV{ elements... }" }
{ $values { "elements" "a list of bytes" } }

View File

@ -8,15 +8,8 @@ TUPLE: byte-vector
{ underlying byte-array }
{ length array-capacity } ;
<PRIVATE
: byte-array>vector ( byte-array length -- byte-vector )
byte-vector boa ; inline
PRIVATE>
: <byte-vector> ( n -- byte-vector )
<byte-array> 0 byte-array>vector ; inline
<byte-array> 0 byte-vector boa ; inline
: >byte-vector ( seq -- byte-vector )
T{ byte-vector f B{ } 0 } clone-like ;
@ -24,11 +17,11 @@ PRIVATE>
M: byte-vector like
drop dup byte-vector? [
dup byte-array?
[ dup length byte-array>vector ] [ >byte-vector ] if
[ dup length byte-vector boa ] [ >byte-vector ] if
] unless ;
M: byte-vector new-sequence
drop [ <byte-array> ] keep >fixnum byte-array>vector ;
drop [ <byte-array> ] [ >fixnum ] bi byte-vector boa ;
M: byte-vector equal?
over byte-vector? [ sequence= ] [ 2drop f ] if ;

View File

@ -332,11 +332,11 @@ cell 8 = [
] unit-test
[ V{ 1 2 } ] [
{ 1 2 3 } 2 [ array>vector ] compile-call
{ 1 2 3 } 2 [ vector boa ] compile-call
] unit-test
[ SBUF" hello" ] [
"hello world" 5 [ string>sbuf ] compile-call
"hello world" 5 [ sbuf boa ] compile-call
] unit-test
[ [ 3 + ] ] [

View File

@ -8,26 +8,19 @@ TUPLE: sbuf
{ underlying string }
{ length array-capacity } ;
<PRIVATE
: string>sbuf ( string length -- sbuf )
sbuf boa ; inline
PRIVATE>
: <sbuf> ( n -- sbuf ) 0 <string> 0 string>sbuf ; inline
: <sbuf> ( n -- sbuf ) 0 <string> 0 sbuf boa ; inline
M: sbuf set-nth-unsafe
[ >fixnum ] [ >fixnum ] [ underlying>> ] tri* set-string-nth ;
M: sbuf new-sequence
drop [ 0 <string> ] [ >fixnum ] bi string>sbuf ;
drop [ 0 <string> ] [ >fixnum ] bi sbuf boa ;
: >sbuf ( seq -- sbuf ) SBUF" " clone-like ; inline
M: sbuf like
drop dup sbuf? [
dup string? [ dup length string>sbuf ] [ >sbuf ] if
dup string? [ dup length sbuf boa ] [ >sbuf ] if
] unless ;
M: sbuf new-resizable drop <sbuf> ;

View File

@ -30,11 +30,6 @@ HELP: >vector
{ $values { "seq" "a sequence" } { "vector" vector } }
{ $description "Outputs a freshly-allocated vector with the same elements as a given sequence." } ;
HELP: array>vector
{ $values { "array" "an array" } { "length" "a non-negative integer" } { "vector" vector } }
{ $description "Creates a new vector using the array for underlying storage with the specified initial length." }
{ $warning "This word is in the " { $vocab-link "vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >vector } " instead." } ;
HELP: 1vector
{ $values { "x" object } { "vector" vector } }
{ $description "Create a new vector with one element." } ;

View File

@ -7,23 +7,17 @@ TUPLE: vector
{ underlying array }
{ length array-capacity } ;
<PRIVATE
: array>vector ( array length -- vector )
vector boa ; inline
PRIVATE>
: <vector> ( n -- vector ) f <array> 0 array>vector ; inline
: <vector> ( n -- vector ) f <array> 0 vector boa ; inline
: >vector ( seq -- vector ) V{ } clone-like ;
M: vector like
drop dup vector? [
dup array? [ dup length array>vector ] [ >vector ] if
dup array? [ dup length vector boa ] [ >vector ] if
] unless ;
M: vector new-sequence drop [ f <array> ] keep >fixnum array>vector ;
M: vector new-sequence
drop [ f <array> ] [ >fixnum ] bi vector boa ;
M: vector equal?
over vector? [ sequence= ] [ 2drop f ] if ;

View File

@ -29,11 +29,6 @@ HELP: >bit-vector
{ $values { "seq" "a sequence" } { "bit-vector" bit-vector } }
{ $description "Outputs a freshly-allocated bit vector with the same elements as a given sequence." } ;
HELP: bit-array>vector
{ $values { "bit-array" "an array" } { "length" "a non-negative integer" } { "bit-vector" bit-vector } }
{ $description "Creates a new bit vector using the array for underlying storage with the specified initial length." }
{ $warning "This word is in the " { $vocab-link "bit-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >bit-vector } " instead." } ;
HELP: ?V{
{ $syntax "?V{ elements... }" }
{ $values { "elements" "a list of booleans" } }

View File

@ -9,15 +9,8 @@ TUPLE: bit-vector
{ underlying bit-array }
{ length array-capacity } ;
<PRIVATE
: bit-array>vector ( bit-array length -- bit-vector )
bit-vector boa ; inline
PRIVATE>
: <bit-vector> ( n -- bit-vector )
<bit-array> 0 bit-array>vector ; inline
<bit-array> 0 bit-vector boa ; inline
: >bit-vector ( seq -- bit-vector )
T{ bit-vector f ?{ } 0 } clone-like ;
@ -25,11 +18,11 @@ PRIVATE>
M: bit-vector like
drop dup bit-vector? [
dup bit-array?
[ dup length bit-array>vector ] [ >bit-vector ] if
[ dup length bit-vector boa ] [ >bit-vector ] if
] unless ;
M: bit-vector new-sequence
drop [ <bit-array> ] keep >fixnum bit-array>vector ;
drop [ <bit-array> ] [ >fixnum ] bi bit-vector boa ;
M: bit-vector equal?
over bit-vector? [ sequence= ] [ 2drop f ] if ;

View File

@ -30,11 +30,6 @@ HELP: >float-vector
{ $description "Outputs a freshly-allocated float vector with the same elements as a given sequence." }
{ $errors "Throws an error if the sequence contains elements other than real numbers." } ;
HELP: float-array>vector
{ $values { "float-array" "an array" } { "length" "a non-negative integer" } { "float-vector" float-vector } }
{ $description "Creates a new float vector using the array for underlying storage with the specified initial length." }
{ $warning "This word is in the " { $vocab-link "float-vectors.private" } " vocabulary because it does not perform type or bounds checks. User code should call " { $link >float-vector } " instead." } ;
HELP: FV{
{ $syntax "FV{ elements... }" }
{ $values { "elements" "a list of real numbers" } }

View File

@ -9,15 +9,8 @@ TUPLE: float-vector
{ underlying float-array }
{ length array-capacity } ;
<PRIVATE
: float-array>vector ( float-array length -- float-vector )
float-vector boa ; inline
PRIVATE>
: <float-vector> ( n -- float-vector )
0.0 <float-array> 0 float-array>vector ; inline
0.0 <float-array> 0 float-vector boa ; inline
: >float-vector ( seq -- float-vector )
T{ float-vector f F{ } 0 } clone-like ;
@ -25,11 +18,11 @@ PRIVATE>
M: float-vector like
drop dup float-vector? [
dup float-array?
[ dup length float-array>vector ] [ >float-vector ] if
[ dup length float-vector boa ] [ >float-vector ] if
] unless ;
M: float-vector new-sequence
drop [ 0.0 <float-array> ] keep >fixnum float-array>vector ;
drop [ 0.0 <float-array> ] [ >fixnum ] bi float-vector boa ;
M: float-vector equal?
over float-vector? [ sequence= ] [ 2drop f ] if ;