]> gitweb.factorcode.org Git - factor.git/commitdiff
This ain't Ruby on Rails son, it's Locals in Literals! Seecrats!
authorEduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Sun, 7 Sep 2008 06:20:07 +0000 (01:20 -0500)
committerEduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Sun, 7 Sep 2008 06:20:07 +0000 (01:20 -0500)
basis/locals/locals.factor

index 5f237dd86b9954ae2df999418bb4d9be042eebc2..abf1041c218529bb7181e154d23f1ead6c307412 100755 (executable)
@@ -1,12 +1,14 @@
 ! 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
@@ -198,6 +200,40 @@ M: object lambda-rewrite* , ;
 
 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>