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

Forth Programmer’s Handbook

'name' is the name of the word to be defined. (There are no restrictions on the format of name, 'name' is merely an often-used convention that includes the specified character in the name itself.) HOLD is defined in such a way that executing 'name' during pictured editing causes the indicated fill character to be introduced into the output.

In the following example, '.' produces a decimal point at the current position in the pictured numeric output. Then the word .$ is defined to print doubleprecision integers as signed amounts with two decimal places:

: '.'

[CHAR]

.

HOLD

;

: .$ ( d)

SWAP

OVER

DABS <# # # '.'

#S

ROT

SIGN

#> TYPE SPACE ;

The word [CHAR] is used in definitions. At run time, it places on the stack the ASCII value of the first character in the word following it. CHAR is similar, but is used interpretively (i.e., not in definitions).

Glossary

 

 

CHAR

( — char )

Core

 

Parse the word following CHAR in the input stream. Put the ASCII value of the

 

first character of this word on the stack. CHAR is normally used interpretively;

 

see [CHAR] for the equivalent function inside a definition. “care”

 

HOLD

( char — )

Core

 

Append char to the current beginning of the pictured numeric output string.

 

HOLD must occur only inside a <# #> number conversion sequence.

 

[CHAR]

( — char )

Core

At compile time, parse the word following [CHAR] in the input stream. At run time, put the ASCII value of the first character of this word on the stack.

“bracket-care”

2.4.2.3 Processing Special Characters

The normal pictured output capabilities described in the preceding two sections can handle most output requirements. But special cases, such as introducing commas in a number or floating of a character (e.g., $), require special processing.

58 Forth Fundamentals

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