factor/extra/delegate/delegate.factor

48 lines
1.3 KiB
Factor
Raw Normal View History

! Copyright (C) 2007 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: parser generic kernel classes words slots assocs sequences arrays ;
IN: delegate
: define-protocol ( wordlist protocol -- )
swap { } like "protocol-words" set-word-prop ;
: PROTOCOL:
2008-03-16 03:43:00 -04:00
CREATE-WORD dup define-symbol
parse-definition swap define-protocol ; parsing
2008-03-26 19:23:19 -04:00
PREDICATE: protocol < word "protocol-words" word-prop ;
GENERIC: group-words ( group -- words )
M: protocol group-words
"protocol-words" word-prop ;
M: generic group-words
1array ;
M: tuple-class group-words
"slots" word-prop 1 tail ! The first slot is the delegate
! 1 tail should be removed when the delegate slot is removed
dup [ slot-spec-reader ] map
swap [ slot-spec-writer ] map append ;
: define-consult-method ( word class quot -- )
2008-03-17 04:27:41 -04:00
pick add >r swap create-method r> define ;
: define-consult ( class group quot -- )
2008-03-17 04:27:41 -04:00
>r group-words swap r>
[ define-consult-method ] 2curry each ;
: CONSULT:
scan-word scan-word parse-definition swapd define-consult ; parsing
: define-mimic ( group mimicker mimicked -- )
>r >r group-words r> r> [
2007-12-08 03:21:32 -05:00
pick "methods" word-prop at dup
2008-03-17 04:27:41 -04:00
[ >r swap create-method r> word-def define ]
2008-03-05 16:24:13 -05:00
[ 3drop ] if
] 2curry each ;
: MIMIC:
scan-word scan-word scan-word define-mimic ; parsing