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

18 lines
327 B
Forth
Raw Permalink Normal View History

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