Not logged in

Differences From Artifact [9d51704f0da49c59]:

File grep.rx part of check-in [f0269c2f92] - add "grep" example by crc on 2011-03-21 16:22:18. [annotate] [view]

To Artifact [c4a277026873894a]:

File util/grep.rx part of check-in [0400d5b703] - move some stuff into 'util' directory by crc on 2011-03-30 17:18:58. [annotate] Also file grep.rx part of check-in [64f5755778] - smaller grep by crc on 2011-03-24 16:41:11. [annotate] [view]


@@ -1,16 +1,13 @@
 ( "filename"  "substring" grep )
 ( display all lines containing "substring" in "filename" )
 
 {{
-  3 elements base token content
+  2 elements token content
 
   : clean ( $- )
     withLength
     [ dup @ 10 13 within [ 999 swap &! sip ] ifTrue 1+ ] times drop ;
-
-  : tokenize ( $-$$ )
-    32 ^strings'splitAtChar ^strings'chop ;
 
   : getLine ( $-$$ )
     999 ^strings'splitAtChar ^strings'chop ;
 
@@ -19,11 +16,15 @@
 
   : loadSourceData ( $- )
     here swap ^files'slurp here !content heap +! 32 , 0 ,
     @content clean ;
+
+  : eachLine ( $- )
+    [ getLine process dup 1 <> ] while drop ;
+
 ---reveal---
   : grep ( $$- )
     cr here !base
     keepString !token
-    loadSourceData @content [ getLine process dup 1 <> ] while drop
-    @base !heap ;
+    heap [ loadSourceData @content eachLine ] preserve ;
 }}
+