factor/extra/float-vectors/float-vectors.factor

39 lines
1.1 KiB
Factor
Raw Normal View History

2008-01-28 19:15:21 -05:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays kernel kernel.private math sequences
sequences.private growable float-arrays prettyprint.backend
2008-04-20 03:30:52 -04:00
parser accessors ;
2008-01-28 19:15:21 -05:00
IN: float-vectors
TUPLE: float-vector
{ underlying float-array initial: F{ } }
2008-06-29 22:37:57 -04:00
{ length array-capacity } ;
2008-04-20 01:18:27 -04:00
2008-01-28 19:15:21 -05:00
: <float-vector> ( n -- float-vector )
<float-array> 0 float-vector boa ; inline
2008-01-28 19:15:21 -05:00
2008-04-20 01:18:27 -04:00
: >float-vector ( seq -- float-vector )
T{ float-vector f F{ } 0 } clone-like ;
2008-01-28 19:15:21 -05:00
M: float-vector like
drop dup float-vector? [
dup float-array?
2008-07-01 21:19:03 -04:00
[ dup length float-vector boa ] [ >float-vector ] if
2008-01-28 19:15:21 -05:00
] unless ;
2008-04-13 13:54:58 -04:00
M: float-vector new-sequence
drop [ <float-array> ] [ >fixnum ] bi float-vector boa ;
2008-01-28 19:15:21 -05:00
M: float-vector equal?
over float-vector? [ sequence= ] [ 2drop f ] if ;
M: float-array new-resizable drop <float-vector> ;
2008-01-28 19:15:21 -05:00
INSTANCE: float-vector growable
: FV{ \ } [ >float-vector ] parse-literal ; parsing
2008-04-20 01:18:27 -04:00
M: float-vector >pprint-sequence ;
M: float-vector pprint-delims drop \ FV{ \ } ;