From c73264863df50c2bebf7636c189bae49932b5a01 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Thu, 17 Jul 2008 16:45:39 -0500 Subject: [PATCH] self.slots: syntax for accessing slots of an object stored in the self variable --- extra/self/slots/slots.factor | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 extra/self/slots/slots.factor diff --git a/extra/self/slots/slots.factor b/extra/self/slots/slots.factor new file mode 100644 index 0000000000..b07641a062 --- /dev/null +++ b/extra/self/slots/slots.factor @@ -0,0 +1,27 @@ + +USING: kernel words lexer parser sequences accessors self ; + +IN: self.slots + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: define-self-slot-reader ( slot -- ) + [ "->" append current-vocab create dup set-word ] + [ ">>" append search [ self> ] swap suffix ] bi + (( -- value )) define-declared ; + +: define-self-slot-writer ( slot -- ) + [ "->" prepend current-vocab create dup set-word ] + [ ">>" prepend search [ self> swap ] swap suffix [ drop ] append ] bi + (( value -- )) define-declared ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: define-self-slot-accessors ( class -- ) + "slots" word-prop + [ name>> ] map + [ [ define-self-slot-reader ] [ define-self-slot-writer ] bi ] each ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: SELF-SLOTS: scan-word define-self-slot-accessors ; parsing \ No newline at end of file