Download code
From LiteratePrograms
Back to Word_count_(Forth)
Download for Windows: single file, zip
Download for UNIX: single file, zip, tar.gz, tar.bz2
wc.f
1 variable nc 2 variable nw 3 variable nl 4 : wc-pad ( bl? n -- bl? ) 5 dup nc +! 6 pad + pad 7 do i c@ bl > 8 if nw +! 0 9 else drop 1 10 i c@ #lf = if 1 nl +! then 11 then 12 loop ; 13 14 : wc 15 1 16 begin pad 4096 stdin read-file throw 17 dup 18 while wc-pad 19 repeat 2drop ; 20 21 wc nl ? nw ? nc ? cr bye
