1 ! Copyright (C) 2008 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel parser words sequences quotations ;
6 ! Mutating literals in word definitions is not really allowed,
7 ! and the deploy tool takes advantage of this fact to perform
8 ! some aggressive stripping and compression. However, this
9 ! breaks a naive implementation of values. We need to do two
11 ! 1) Store the value in a subclass of identity-tuple, so that
12 ! two quotations from different value words are never equal.
13 ! This avoids bogus merging of values.
14 ! 2) Set the "no-def-strip" word-prop, so that the shaker leaves
15 ! the def>> slot alone, allowing us to introspect it. Otherwise,
16 ! it will get set to [ ] and we would lose access to the
21 TUPLE: value-holder < identity-tuple obj ;
27 dup t "no-def-strip" set-word-prop
28 T{ value-holder } clone [ obj>> ] curry
29 (( -- value )) define-declared ; parsing
31 : set-value ( value word -- )
35 scan-word literalize parsed
36 \ set-value parsed ; parsing
38 : get-value ( word -- value )
41 : change-value ( word quot -- )
42 [ [ get-value ] dip call ] [ drop ] 2bi set-value ; inline