Clean up some duplication
[factor/jcg.git] / extra / self / slots / slots.factor
blobb07641a062f33b77fb9e6dbfc54521b2a19dc659
2 USING: kernel words lexer parser sequences accessors self ;
4 IN: self.slots
6 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8 : define-self-slot-reader ( slot -- )
9   [ "->" append current-vocab create dup set-word ]
10   [ ">>" append search [ self> ] swap suffix      ] bi
11   (( -- value )) define-declared ;
13 : define-self-slot-writer ( slot -- )
14   [ "->" prepend current-vocab create dup set-word ]
15   [ ">>" prepend search [ self> swap ] swap suffix [ drop ] append ] bi
16   (( value -- )) define-declared ;
18 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20 : define-self-slot-accessors ( class -- )
21   "slots" word-prop
22   [ name>> ] map
23   [ [ define-self-slot-reader ] [ define-self-slot-writer ] bi ] each ;
25 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 : SELF-SLOTS: scan-word define-self-slot-accessors ; parsing