2005-02-18 20:37:01 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-12-18 23:18:32 -05:00
|
|
|
IN: generic
|
2005-04-25 19:54:21 -04:00
|
|
|
USING: errors hashtables kernel lists namespaces parser
|
|
|
|
sequences strings words vectors ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
! Union metaclass for dispatch on multiple classes.
|
|
|
|
SYMBOL: union
|
2004-07-28 19:02:24 -04:00
|
|
|
|
2005-08-03 18:47:32 -04:00
|
|
|
: union-predicate ( members -- list )
|
2004-12-18 23:18:32 -05:00
|
|
|
[
|
2005-08-22 14:29:43 -04:00
|
|
|
"predicate" word-prop
|
|
|
|
[ dup ] swap add [ drop t ] cons
|
|
|
|
] map [ drop f ] swap alist>quot ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-08-14 18:13:16 -04:00
|
|
|
: set-members ( class members -- )
|
|
|
|
2dup [ types ] map concat "types" set-word-prop
|
|
|
|
"members" set-word-prop ;
|
|
|
|
|
2005-08-03 18:47:32 -04:00
|
|
|
: define-union ( class predicate members -- )
|
2004-12-23 18:26:04 -05:00
|
|
|
#! We have to turn the f object into the f word, same for t.
|
2005-08-14 18:13:16 -04:00
|
|
|
3dup nip set-members pick union define-class
|
2005-08-03 18:47:32 -04:00
|
|
|
union-predicate define-predicate ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
|
|
|
PREDICATE: word union metaclass union = ;
|