]> gitweb.factorcode.org Git - factor.git/blob - basis/specialized-vectors/functor/functor.factor
Merge branch 'master' into experimental (untested!)
[factor.git] / basis / specialized-vectors / functor / functor.factor
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
6
7 FUNCTOR: define-vector ( T -- )
8
9 A   IS      ${T}-array
10 <A> IS      <${A}>
11
12 V   DEFINES ${T}-vector
13 <V> DEFINES <${V}>
14 >V  DEFINES >${V}
15 V{  DEFINES ${V}{
16
17 WHERE
18
19 TUPLE: V { underlying A } { length array-capacity } ;
20
21 : <V> <A> execute 0 V boa ; inline
22
23 M: V like
24     drop dup V instance? [
25         dup A instance? [ dup length V boa ] [ >V execute ] if
26     ] unless ;
27
28 M: V new-sequence drop [ <A> execute ] [ >fixnum ] bi V boa ;
29
30 M: A new-resizable drop <V> execute ;
31
32 M: V equal? over V instance? [ sequence= ] [ 2drop f ] if ;
33
34 : >V V new clone-like ; inline
35
36 M: V pprint-delims drop V{ \ } ;
37
38 M: V >pprint-sequence ;
39
40 M: V pprint* pprint-object ;
41
42 : V{ \ } [ >V execute ] parse-literal ; parsing
43
44 INSTANCE: V growable
45
46 ;FUNCTOR