retroforth/example/dictionary-stats.retro
crc 6a4aaf8eac prefix: namespace is now sigil:, rename words, update examples, update docs
FossilOrigin-Name: 25cf19660ab7728d7bfee2722ea826a8a438faf92b2504b28d922d2958906aed
2021-03-30 11:58:25 +00:00

30 lines
660 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-of 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
~~~