Not logged in
Overview
SHA1 Hash:268a006de86cd26f9ea4d4934aec2db10ce8f0b0
Date: 2011-03-24 16:45:34
User: crc
Comment:add 'wc' example
Timelines: family | ancestors | descendants | both | trunk
Other Links: files | manifest
Tags And Properties
Changes
[hide diffs]    [patch]

Added wc.rx version [a433321878465eba]

@@ -0,0 +1,28 @@
+{{
+  3 elements content lines words
+
+  : clean ( $- )
+    withLength
+    [ dup @ 10 13 within [ 999 swap &! sip ] ifTrue 1+ ] times drop ;
+
+  : remaining ( $-n )
+    32 ^strings'splitAtChar ^strings'chop drop ;
+
+  : getLine ( $-$$ )
+    999 ^strings'splitAtChar ^strings'chop ;
+
+  : countWords ( $- )
+    [ words ++ remaining dup 1 <> ] while drop ;
+
+  : loadSourceData ( $- )
+    here swap ^files'slurp here !content heap +! 32 , 0 ,
+    @content clean ;
+
+  : countLines ( $- )
+    [ getLine lines ++ countWords dup 1 <> ] while drop ;
+---reveal---
+  : wc ( $-nnn )
+    lines words [ 0 swap ! ] bi@
+    heap [ loadSourceData @content countLines ] preserve
+    @lines @words @content getLength [ 1- ] tri@ ;
+}}