Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Conklin E.K.Forth programmer's handbook.2000.pdf
Скачиваний:
321
Добавлен:
23.08.2013
Размер:
2.04 Mб
Скачать

Forth Programmer’s Handbook

Longer constructs should be structured like this:

<code to generate flag>__if

___<true clause> then

<code to generate flag>__if

___<true clause> else

___<false clause> then

6.2.4 do…loop Structures

In do…loop constructs that occupy no more than one line, two spaces should be used both before and after each do or loop.

<code to calculate limits>__do__xxx__loop__

Longer constructs should be structured like this:

<code to calculate limits>__do

___<body> loop

The longer +loop constructs should be structured like this:

<code to calculate limits>__do

___<body>

<incremental value>_+loop

6.2.5 begin…while…repeat Structures

In begin…while…repeat constructs that occupy that occupy no more than one line, two spaces should be used both before and after each begin, while, or repeat.

__begin__<flag code>__while__<body>__repeat__

188 Programming Style

Forth Programmer’s Handbook

Longer constructs:

begin__<short flag code>__while

___<body> repeat begin

___<long flag code> while

___<body> repeat

6.2.6 begin…until…again Structures

In begin…until and begin…again constructs that occupy no more than one line, two spaces should be used both before and after each begin, until, or again.

__begin__<body>__until __begin__<body>__again

Longer constructs:

begin

___<body> until begin

___<body> again

6.2.7 Block Comments

Block comments begin with \_. All text after the space is ignored until after the next new line. It would be possible to delimit block comments with parentheses, but the use of parentheses is reserved by convention for stack comments.

Precede each non-trivial definition with a block comment giving a clear and concise explanation of what the word does. Put more comments at the very

Programming Style 189

Forth Programmer’s Handbook

beginning of the file to describe external words which could be used from the User Interface.

6.2.8 Stack Comments

Stack comments begin with (_ and end with ). Use stack liberally within definitions. Try to structure each definition so that, when you put stack comments at the end of each line, the stack picture makes a nice pattern.

: name (stack before -- stack after)

___xxx xxx bar ( stack condition after the execution of bar)

___xxx xxx foo ( stack condition after the execution of foo)

___xxx xxx dup ( stack condition after the execution of dup)

6.2.9 Return Stack Comments

Return stack comments are also delimited with parentheses. In addition, the notation r: is used at the beginning of the return stack comment to differentiate it from a data stack comment.

Place return stack comments on any line that contains one or more words that cause the return stack to change. (This limitation is a practical one; it is often difficult to do otherwise due to lack of space.) The words >r and r> must be paired inside colon definitions and inside do…loop constructs.

: name ( stack before -- stack after )

___xxx >r ( r:addr )

___xxx r> ( r: )

6.2.10 Numbers

Hexadecimal numbers should be typed in a lower case. If a given number contains more the four digits, the number may be broken into groups of four digits with periods. For example:

190 Programming Style

Соседние файлы в предмете Электротехника