Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Rich H.J for C programmers.2006.pdf
Скачиваний:
18
Добавлен:
23.08.2013
Размер:
1.79 Mб
Скачать

The omission produces a subtle but fatal change in the parsing order. As the Dictionary says, "it may be necessary to parenthesize an adverbial or conjunctival phrase that produces anything other than a noun or verb". Now you see why.

Undefined Words

 

If you try to execute a nonexistent verb, you get an error:

 

z 5

error: z

|value

|

 

z 5

However, that error occurs during execution of the name, not during its parsing. During parsing, an undefined name is assumed to be a verb of infinite rank. This allows you to write verbs that refer to each other, and relieves you from having to be scrupulous about the order in which you define verbs. For example:

a =: z

This produces a verb a which, when executed, will execute z. z =: +

a 5

5

With z defined, a executes correctly. Of course, it's OK to assign z to another verb too: b =: z

b 5

5

Now, can you tell me what +/@b 1 2 3 will do? Take a minute to figure it out (Hint: note that I used @ rather than @:).

+/@b 1 2 3 1 2 3

Because b has rank 0, +/@b also has rank zero, so the 'summing' is applied to atoms individually and we get a list result. Do you think +/@a 1 2 3 will have the same result?

+/@a 1 2 3

6

Even though a has the same value as b, its rank is different. a's rank was assigned when it was parsed, and at that time z was assumed to have infinite rank. b's rank was assigned when it was parsed too, but by that time z had been defined with rank 0. You can win a lot of bar bets with this one if you hang out with the right crowd.

230