retroforth/example/DictionaryStats.forth
crc e71709b303 begin work on 2018.6; this release *will* make some changes that break existing code in small ways
FossilOrigin-Name: 2ea7e4d5f74070041c454af65713a478ebe2a9d71bbc9e6bb6add6c256351765
2018-04-25 16:51:46 +00:00

30 lines
654 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 puts
~~~
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 puts
~~~
And without the prefixes...
~~~
#0 #0 [ d:name dup $: s:index-of n:inc + s:length + [ n:inc ] dip ] d:for-each swap /
'Average_name_without_namespace:_%n\n s:format puts
~~~
Longest name are...
~~~
#0 [ d:name s:length n:max ] d:for-each
'Longest_names_are_%n_characters\n s:format puts
~~~