factor/library/generic/complement.factor

32 lines
932 B
Factor
Raw Normal View History

2005-01-13 14:41:08 -05:00
! Copyright (C) 2005 Slava Pestov.
2005-02-18 20:37:01 -05:00
! See http://factor.sf.net/license.txt for BSD license.
2005-01-13 14:41:08 -05:00
IN: generic
2005-02-18 20:37:01 -05:00
USING: errors hashtables kernel lists math parser strings
sequences vectors words ;
2005-01-13 14:41:08 -05:00
! Complement metaclass, contains all objects not in a certain class.
SYMBOL: complement
complement [
( generic vtable definition class -- )
2005-01-23 16:47:28 -05:00
drop num-types [
2005-08-14 18:13:16 -04:00
>r 3dup r> type>class
2005-07-31 23:38:33 -04:00
dup [ add-method ] [ 2drop 2drop ] ifte
] each 3drop
] "add-method" set-word-prop
2005-01-13 14:41:08 -05:00
: complement-predicate ( complement -- list )
"predicate" word-prop [ not ] append ;
2005-01-13 14:41:08 -05:00
2005-08-14 18:13:16 -04:00
: complement-types ( class -- types )
"complement" word-prop types object types seq-diff ;
2005-02-21 21:26:20 -05:00
: define-complement ( class complement -- )
2dup "complement" set-word-prop
dupd complement-predicate "predicate" set-word-prop
2005-08-14 18:13:16 -04:00
dup complement-types "types" set-word-prop
2005-01-13 14:41:08 -05:00
complement define-class ;
PREDICATE: word complement metaclass complement = ;