RosettaCodeData/Task/Letter-frequency/Forth/letter-frequency.fth

18 lines
315 B
Forth
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
create counts 26 cells allot
: freq ( filename -- )
counts 26 cells erase
slurp-file bounds do
i c@ 32 or 'a -
dup 0 26 within if
cells counts +
1 swap +!
else drop then
loop
26 0 do
cr [char] ' emit 'a i + emit ." ': "
counts i cells + @ .
loop ;
s" example.txt" freq