]> gitweb.factorcode.org Git - factor.git/blob - core/generic/generic.factor
53d5edee689489d9671617ed1e267edb61f157a9
[factor.git] / core / generic / generic.factor
1 ! Copyright (C) 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: generic
4 USING: words kernel sequences namespaces hashtables ;
5
6 PREDICATE: compound generic ( word -- ? )
7     "combination" word-prop ;
8
9 M: generic definer drop \ G: ;
10
11 : make-generic ( word -- )
12     dup dup "combination" word-prop call define-compound ;
13
14 : ?make-generic ( word -- )
15     bootstrapping? get
16     [ [ ] define-compound ] [ make-generic ] if ;
17
18 : init-methods ( word -- )
19      dup "methods" word-prop
20      [ drop ] [ H{ } clone "methods" set-word-prop ] if ;
21
22 ! Defining generic words
23
24 : bootstrap-combination ( quot -- quot )
25     global [ [ dup word? [ target-word ] when ] map ] bind ;
26
27 : define-generic* ( word combination -- )
28     bootstrap-combination
29     dupd "combination" set-word-prop
30     dup init-methods ?make-generic ;
31
32 : generic-tags ( word -- seq )
33     "methods" word-prop hash-keys [ types ] map concat prune ;