1 ! Copyright (C) 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: words kernel sequences namespaces hashtables ;
6 PREDICATE: compound generic ( word -- ? )
7 "combination" word-prop ;
9 M: generic definer drop \ G: ;
11 : make-generic ( word -- )
12 dup dup "combination" word-prop call define-compound ;
14 : ?make-generic ( word -- )
16 [ [ ] define-compound ] [ make-generic ] if ;
18 : init-methods ( word -- )
19 dup "methods" word-prop
20 [ drop ] [ H{ } clone "methods" set-word-prop ] if ;
22 ! Defining generic words
24 : bootstrap-combination ( quot -- quot )
25 global [ [ dup word? [ target-word ] when ] map ] bind ;
27 : define-generic* ( word combination -- )
29 dupd "combination" set-word-prop
30 dup init-methods ?make-generic ;
32 : generic-tags ( word -- seq )
33 "methods" word-prop hash-keys [ types ] map concat prune ;