2006-08-02 02:49:23 -04:00
|
|
|
! Copyright (C) 2006 Slava Pestov.
|
2006-05-10 02:18:25 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2004-12-13 00:13:54 -05:00
|
|
|
IN: generic
|
2006-08-02 03:10:09 -04:00
|
|
|
USING: words kernel sequences namespaces hashtables ;
|
2005-09-16 02:39:33 -04:00
|
|
|
|
|
|
|
PREDICATE: compound generic ( word -- ? )
|
|
|
|
"combination" word-prop ;
|
|
|
|
|
|
|
|
M: generic definer drop \ G: ;
|
2005-04-24 20:57:37 -04:00
|
|
|
|
2005-05-14 21:15:50 -04:00
|
|
|
: make-generic ( word -- )
|
2005-08-23 15:50:32 -04:00
|
|
|
dup dup "combination" word-prop call define-compound ;
|
2004-12-18 23:18:32 -05:00
|
|
|
|
2005-12-19 23:18:15 -05:00
|
|
|
: ?make-generic ( word -- )
|
2006-01-08 20:41:31 -05:00
|
|
|
bootstrapping? get
|
|
|
|
[ [ ] define-compound ] [ make-generic ] if ;
|
2005-12-19 23:18:15 -05:00
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
: init-methods ( word -- )
|
2005-08-22 14:29:43 -04:00
|
|
|
dup "methods" word-prop
|
2005-10-29 23:25:38 -04:00
|
|
|
[ drop ] [ H{ } clone "methods" set-word-prop ] if ;
|
2004-12-29 18:01:23 -05:00
|
|
|
|
2004-12-13 00:13:54 -05:00
|
|
|
! Defining generic words
|
2005-08-22 15:33:18 -04:00
|
|
|
|
|
|
|
: bootstrap-combination ( quot -- quot )
|
2005-11-24 19:02:20 -05:00
|
|
|
global [ [ dup word? [ target-word ] when ] map ] bind ;
|
2005-08-22 15:33:18 -04:00
|
|
|
|
2005-08-22 14:29:43 -04:00
|
|
|
: define-generic* ( word combination -- )
|
2005-08-22 15:33:18 -04:00
|
|
|
bootstrap-combination
|
2005-08-22 14:29:43 -04:00
|
|
|
dupd "combination" set-word-prop
|
2005-12-19 23:18:15 -05:00
|
|
|
dup init-methods ?make-generic ;
|
2006-08-02 03:10:09 -04:00
|
|
|
|
|
|
|
: generic-tags ( word -- seq )
|
|
|
|
"methods" word-prop hash-keys [ types ] map concat prune ;
|