1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs kernel kernel.private namespaces quotations
4 generic math sequences combinators words classes.algebra arrays
6 IN: generic.standard.engines
12 GENERIC: engine>quot ( engine -- quot )
14 : engines>quots ( assoc -- assoc' )
15 [ engine>quot ] assoc-map ;
17 : engines>quots* ( assoc -- assoc' )
18 [ over assumed [ engine>quot ] with-variable ] assoc-map ;
20 : if-small? ( assoc true false -- )
21 [ dup assoc-size 4 <= ] 2dip if ; inline
23 : linear-dispatch-quot ( alist -- quot )
24 default get [ drop ] prepend swap
26 [ [ dup ] swap [ eq? ] curry compose ]
32 : split-methods ( assoc class -- first second )
33 [ [ nip class<= not ] curry assoc-filter ]
34 [ [ nip class<= ] curry assoc-filter ] 2bi ;
36 : convert-methods ( assoc class word -- assoc' )
37 over [ split-methods ] 2dip pick assoc-empty? [
40 [ execute ] dip pick set-at
43 : (picker) ( n -- quot )
48 [ 1- (picker) [ dip swap ] curry ]
51 : picker ( -- quot ) \ (dispatch#) get (picker) ;
53 GENERIC: extra-values ( generic -- n )