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

Forth Programmer’s Handbook

words in the following glossary are provided.

As an example of their use, you could compare a string whose address is returned by NAME with one temporarily stored at PAD, testing as follows:

PAD <length> DUP NAME SWAP COMPARE

SEARCH is generally used to find a short string in a longer string. It is used by the Forth editor.

Glossary

 

 

 

COMPARE

( c-addr1 u1 c-addr2 u2 — n )

String

 

 

Compare the string specified by c-addr1 u1 to the string specified by c-addr2 u2

 

 

and return a result code n. The strings are compared character-by-character,

 

 

beginning at the given addresses, up to the length of the shorter string or until

 

 

a difference is found. If the two strings are identical and of equal lengths, n is

 

 

zero. If the two strings are identical up to the length of the shorter string, n is

 

 

-1 if u1 is less than u2, and +1 otherwise. If the two strings are not identical up

 

 

to the length of the shorter string, n is -1 if the first non-matching character in

 

 

the string at c-addr1 has a lesser numeric value than the corresponding charac-

 

 

ter in the string at c-addr2, and +1 otherwise.

 

SEARCH

( c-addr1 u1 c-addr2 u2 — c-addr3 u3 flag )

String

 

 

Search for a match for the string c-addr2 u2 in the string c-addr1 u1 (which is pre-

 

 

sumed to be longer). If a match is found, return true with the address c-addr3 of

 

 

the first matching character and the length u3 of the remainder of the string. If

 

 

no match is found, c-addr3 = c-addr1, u3 = u1, and flag is false.

 

 

 

PAD, Section 2.3.1

 

References

 

 

2.4 NUMERIC OUTPUT WORDS

Numeric output words allow the display of numeric quantities as ASCII characters. This output is generally directed to the terminal.

Numeric output words are divided into two categories: normal output words

52 Forth Fundamentals

Forth Programmer’s Handbook

and conversion output words. The latter allow the picturing of ASCII text, in a manner that resembles COBOL picturing.

All numeric output words produce ASCII text, which is the ASCII number expressed in the current BASE. BASE is a user variable containing the current conversion radix, and is controlled with the appropriate radix word (e.g., DECIMAL or HEX) or by setting the value of BASE directly. For example, BASE may be set to binary by:

2 BASE !

References Numbers, Section 1.1.6

2.4.1 Standard Numeric Output Words

Several standard words allow displaying singleor double-precision signed numbers in various formats. All of them remove their arguments from the stack. To preserve a number you are about to display, DUP it first. Each display word produces an output string that consists of the following characters:

1.If the number is negative, a leading minus sign (hyphen).

2.The absolute value of the number, with leading zeroes suppressed. (The number zero results in a single zero in the output.)

3.In some cases, a trailing blank.

The standard numeric output words are:

Glossary

.

( n — )

Core

 

Remove the top of stack item and display it as a signed single-precision integer

 

followed by one space. “dot”

 

.R

( n1 +n2 — )

Core Ext

Display signed single-precision integer n1 with leading spaces, to fill a field of width +n2, right-justified. This word expects positive integer n2 on top of the stack to specify the length of the output field. The width of the printed string

Forth Fundamentals 53

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