1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: functors sequences sequences.private growable
4 prettyprint.custom kernel words classes math parser ;
5 IN: specialized-vectors.functor
7 FUNCTOR: define-vector ( T -- )
19 TUPLE: V { underlying A } { length array-capacity } ;
21 : <V> ( capacity -- vector ) <A> execute 0 V boa ; inline
24 drop dup V instance? [
25 dup A instance? [ dup length V boa ] [ >V execute ] if
28 M: V new-sequence drop [ <A> execute ] [ >fixnum ] bi V boa ;
30 M: A new-resizable drop <V> execute ;
32 M: V equal? over V instance? [ sequence= ] [ 2drop f ] if ;
34 : >V ( seq -- vector ) V new clone-like ; inline
36 M: V pprint-delims drop V{ \ } ;
38 M: V >pprint-sequence ;
40 M: V pprint* pprint-object ;
42 : V{ \ } [ >V execute ] parse-literal ; parsing