factor/library/generic/generic.factor

34 lines
934 B
Factor
Raw Normal View History

2006-08-02 02:49:23 -04:00
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: generic
2006-08-02 03:10:09 -04:00
USING: words kernel sequences namespaces hashtables ;
PREDICATE: compound generic ( word -- ? )
"combination" word-prop ;
M: generic definer drop \ G: ;
2005-04-24 20:57:37 -04:00
: make-generic ( word -- )
2005-08-23 15:50:32 -04:00
dup dup "combination" word-prop call define-compound ;
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
[ drop ] [ H{ } clone "methods" set-word-prop ] if ;
2004-12-29 18:01:23 -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 ;