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
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
union [
|
2005-08-14 17:33:45 -04:00
|
|
|
"members" word-prop [ builtin-supertypes ] map concat
|
2005-03-05 14:45:23 -05:00
|
|
|
] "builtin-supertypes" set-word-prop
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
union [
|
2004-12-23 23:55:22 -05:00
|
|
|
( generic vtable definition class -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
"members" word-prop [ >r 3dup r> add-method ] each 3drop
|
|
|
|
] "add-method" set-word-prop
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-08-03 18:47:32 -04:00
|
|
|
: union-predicate ( members -- list )
|
2004-12-18 23:18:32 -05:00
|
|
|
[
|
|
|
|
[
|
|
|
|
\ dup ,
|
2005-04-16 00:23:27 -04:00
|
|
|
unswons "predicate" word-prop %
|
2004-12-18 23:18:32 -05:00
|
|
|
[ drop t ] ,
|
|
|
|
union-predicate ,
|
|
|
|
\ ifte ,
|
|
|
|
] make-list
|
|
|
|
] [
|
|
|
|
[ drop f ]
|
|
|
|
] ifte* ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
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-03 18:47:32 -04:00
|
|
|
3dup nip "members" set-word-prop
|
|
|
|
pick union define-class
|
|
|
|
union-predicate define-predicate ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
|
|
|
PREDICATE: word union metaclass union = ;
|