1 ! Copyright (C) 2007 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: splitting grouping classes.tuple classes math kernel
4 sequences arrays accessors ;
7 TUPLE: tuple-array { seq read-only } { class read-only } ;
9 : <tuple-array> ( length class -- tuple-array )
11 new tuple>array 1 tail
12 [ <repetition> concat ] [ length ] bi <sliced-groups>
13 ] [ ] bi tuple-array boa ;
16 [ seq>> nth ] [ class>> ] bi prefix >tuple ;
18 M: tuple-array set-nth ( elt n seq -- )
19 [ tuple>array 1 tail ] 2dip seq>> set-nth ;
21 M: tuple-array new-sequence
22 class>> <tuple-array> ;
24 : >tuple-array ( seq -- tuple-array )
26 0 over first class <tuple-array> clone-like
30 drop dup tuple-array? [ >tuple-array ] unless ;
32 M: tuple-array length seq>> length ;
34 INSTANCE: tuple-array sequence