retroforth/example/dictionary-stats.retro
crc c8a5b047bd image: rename s:index-of, s:index-of-string, a:index-of, a:index-of-string
FossilOrigin-Name: 88416f7a177a6171739a75db5ad4d399735ecd29836424897629ca1787d776d2
2021-06-04 18:34:59 +00:00

30 lines
662 B
Forth

It's sometimes interesting to take some measurements of dictionary names.
Determine the number of words in the dictionary.
~~~
#0 [ drop n:inc ] d:for-each
'%n_names_defined\n s:format s:put
~~~
Determine the average length of a word name.
~~~
#0 [ d:name s:length + ] d:for-each
#0 [ drop n:inc ] d:for-each
/ 'Average_name_length:_%n\n s:format s:put
~~~
And without the namespaces...
~~~
#0 #0 [ d:name dup $: s:index/char n:inc + s:length + [ n:inc ] dip ] d:for-each swap /
'Average_name_without_namespace:_%n\n s:format s:put
~~~
Longest name are...
~~~
#0 [ d:name s:length n:max ] d:for-each
'Longest_names_are_%n_characters\n s:format s:put
~~~