Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C to Forth (was Ting)

65 views
Skip to first unread message

Robert L.

unread,
Jul 26, 2017, 1:32:53 PM7/26/17
to
Paul Rubin wrote:

> I think except for implementations of Forth itself, Forth programs don't
> tend to be of the type that uses a lot of strings as data. I'm probably
> more accustomed than most hardcore Forthers to programming in that
> style. But from that perspective, tables indexed by strings (basically,
> Forth word lists with a different interface) are very useful. Most
> languages in significantly wide use these days supply them.

I suppose that I shouldn't have been astonished that you had
to explain "tables indexed by strings" and their widespread
use to Mrs. Rather.

Using a "table indexed by strings", let's count the occurrences
of each word in that post.

(use srfi-13) ; string-tokenize
(use srfi-14) ; character-set library
(use srfi-69) ; hash-tables
(use srfi-95) ; a more capable sort
(use loopy-loop)

(define text
"I think except for implementations of Forth itself, Forth programs don't
tend to be of the type that uses a lot of strings as data. I'm probably
more accustomed than most hardcore Forthers to programming in that
style. But from that perspective, tables indexed by strings (basically,
Forth word lists with a different interface) are very useful. Most
languages in significantly wide use these days supply them.")

(define table (make-hash-table initial: 0))

(define words
(string-tokenize text (string->char-set "'" char-set:letter)))

(for-each
(cut hash-table-update! table <> add1)
words)

(define sorted (sort (hash-table->alist table) string<? car))

(define word-width
(apply max (map (compose string-length car) sorted)))

(loop (((word . count) <- in-list sorted))
(printf "~a ~a\n" (string-pad-right word word-width) count))

But 1
Forth 3
Forthers 1
I 1
I'm 1
Most 1
a 2
accustomed 1
are 1
as 1
basically 1
be 1
by 1
data 1
days 1
different 1
don't 1
except 1
for 1
from 1
hardcore 1
implementations 1
in 2
indexed 1
interface 1
itself 1
languages 1
lists 1
lot 1
more 1
most 1
of 3
perspective 1
probably 1
programming 1
programs 1
significantly 1
strings 2
style 1
supply 1
tables 1
tend 1
than 1
that 3
the 1
them 1
these 1
think 1
to 2
type 1
use 1
useful 1
uses 1
very 1
wide 1
with 1
word 1


--
[E]verything that happens in the world is for the benefit of the Jewish
People.... G-D ... created the world for the sake of the Jewish People, and it
is our responsibility to implement the Torah---absolute morality and the
blueprint of creation---in it.
www.IsraelNationalNews.com/Articles/Article.aspx/2125#.UUnBZxx4xn8
0 new messages