retroforth/doc/book/Programming-Techniques-Unu
crc ea11871f3b book files now under doc/book
FossilOrigin-Name: d9fdb9041d22c8587afdc7e70aa1f85d85d66faa2c425ddb4b420b935a75037e
2019-03-29 20:00:20 +00:00

43 lines
961 B
Text

# Unu: Simple, Literate Source Files
RETRO is written in a literate style. Most of the sources
are in a format called Unu. This allows easy mixing of
commentary and code blocks, making it simple to document
the code.
As an example,
# Determine The Average Word Name Length
To determine the average length of a word name two values
are needed. First, the total length of all names in the
Dictionary:
~~~
#0 [ d:name s:length + ] d:for-each
~~~
And then the number of words in the Dictionary:
~~~
#0 [ drop n:inc ] d:for-each
~~~
With these, a simple division is all that's left.
~~~
/
~~~
Finally, display the results:
~~~
'Average_name_length:_%n\n s:format s:put
~~~
This illustrates the format. Only code in the fenced blocks
(between \~~~ pairs) get extracted and run.
(Note: this only applies to *source files*; fences are not used
when entering code interactively).