Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #42360
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Oforth: tabulate words in file |
| Date | 2015-10-04 21:07 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mus4do$gl0$1@dont-email.me> (permalink) |
Count how many times each word occurs in a file.
We'll use Alice in Wonderland.
: tokenize { groupWith(#isLetter) filter( #[ first isLetter ] ) }
: slurp-file(filename) {| file |
File newMode(filename, File.BINARY) -> file
file open( File.READ )
file readBytesWith(file size, MemBuffer new) asString
file close }
: clip(limit,array) {array left(limit ifTrue: [limit] else: [array size])}
: dofile(filename, limit) {
filename slurp-file tokenize map(#toLower)
sort group map( #[ dup first swap size [,] ] )
limit clip
apply( #[dup first . last println] ) }
dofile("alice30.txt", 25)
a 659
abide 1
able 1
about 97
above 4
absence 1
absurd 2
accept 1
acceptance 1
accepts 1
accident 2
accidentally 1
accomplish 1
account 1
accounting 1
accounts 1
accusation 1
accustomed 1
ache 1
across 5
act 1
actually 1
ada 1
added 23
adding 1
--
After being told there was no money, the attackers tore off the woman's clothes
and raped her until five others arrived, according to the documents. The new
arrivals took turns having sex with her and then sodomized her.... At gunpoint,
the assailants forced the mother and son to have sex.
www.sun-sentinel.com/local/palm-beach/sfl-flpdunbar0822nbaug22-story.html
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Oforth: tabulate words in file "WJ" <w_a_x_man@yahoo.com> - 2015-10-04 21:07 +0000 Re: Oforth: tabulate words in file "WJ" <w_a_x_man@yahoo.com> - 2015-11-26 14:35 +0000
csiph-web