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
|
2019-10-18 09:05:08 -04:00
|
|
|
USING: words kernel sequences namespaces assocs hashtables
|
|
|
|
|
definitions ;
|
2005-09-16 02:39:33 -04:00
|
|
|
|
|
|
|
|
PREDICATE: compound generic ( word -- ? )
|
|
|
|
|
"combination" word-prop ;
|
|
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
M: generic definer drop \ G: \ ; ;
|
|
|
|
|
|
|
|
|
|
M: generic definition "combination" word-prop ;
|
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 -- )
|
2019-10-18 09:05:08 -04:00
|
|
|
[ [ ] define-compound ] [ make-generic ] if-bootstrapping ;
|
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
|
2019-10-18 09:05:08 -04:00
|
|
|
?<hashtable>
|
|
|
|
|
"methods" set-word-prop ;
|
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
|
|
|
|
2019-10-18 09:05:08 -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 )
|
2019-10-18 09:05:08 -04:00
|
|
|
"methods" word-prop keys [ types ] map concat prune ;
|