retroforth/example/DictionaryStats.forth
crc 89567d9322 example/DictionaryStats now has average length w/o namespace
FossilOrigin-Name: 3b5195816ef3c8f7397ed07d2d16c3b2660494d5897068ac3c4a45b2417f2ddf
2017-10-24 14:55:53 +00:00

30 lines
674 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:with-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:with-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:with-format puts
~~~
Longest name are...
~~~
#0 [ d:name s:length n:max ] d:for-each
'Longest_names_are_%n_characters\n s:with-format puts
~~~