! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel namespaces sequences sequences.private assocs math
-parser words quotations debugger macros arrays macros splitting
-combinators prettyprint.backend definitions prettyprint
-hashtables prettyprint.sections sets sequences.private effects
-effects.parser generic generic.parser compiler.units accessors
-locals.backend memoize macros.expander lexer
-stack-checker.known-words ;
+ vectors strings generalizations
+ parser words quotations debugger macros arrays macros splitting
+ combinators prettyprint.backend definitions prettyprint
+ hashtables prettyprint.sections sets sequences.private effects
+ effects.parser generic generic.parser compiler.units accessors
+ locals.backend memoize macros.expander lexer
+ stack-checker.known-words ;
+
IN: locals
! Inspired by
M: object local-rewrite* , ;
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+! Broil is used to support locals in literals
+
+DEFER: [broil]
+
+: broil-element ( obj -- quot )
+ {
+ { [ dup number? ] [ 1quotation ] }
+ { [ dup string? ] [ 1quotation ] }
+ { [ dup sequence? ] [ [broil] ] }
+ { [ dup local? ] [ 1quotation ] }
+ { [ dup word? ] [ literalize 1quotation ] }
+ { [ t ] [ 1quotation ] }
+ }
+ cond ;
+
+: [broil] ( seq -- quot )
+ [ [ broil-element ] map concat >quotation ]
+ [ length ]
+ [ ]
+ tri
+ [ nsequence ] curry curry compose ;
+
+MACRO: broil ( seq -- quot ) [broil] ;
+
+! Engage broil on arrays and vectors. Can't do it on 'sequence'
+! because that will pick up strings and integers. What do do...
+
+M: array local-rewrite* ( array -- ) [broil] % ;
+M: vector local-rewrite* ( vector -- ) [broil] % ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
: make-local ( name -- word )
"!" ?tail [
<local-reader>