home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / forthmacs / htmldocs / !Forthmacs / docs / html / vocabulari < prev    next >
Encoding:
Text File  |  1996-02-23  |  26.2 KB  |  480 lines

  1. <!-- Forthmacs Formatter generated HTML output -->
  2. <html>
  3. <head>
  4. <title>Vocabularies and Search Order</title>
  5. </head>
  6. <body>
  7. <h1>Vocabularies and Search Order</h1>
  8. <hr>
  9. <p>
  10. This chapter is a tutorial describing vocabularies and search order control.  It 
  11. also describes the contents and purpose of each of the vocabularies that are 
  12. part of the normal Risc-OS Forthmacs system.  
  13. <p>
  14. A vocabulary is a list of Forth words.  The Forth 83 standard defines a 
  15. vocabulary as: 
  16. <p>
  17. A vocabulary is an ordered list of word definitions.  Vocabularies are an 
  18. advantage in separating different word definitions that may have the same name.  
  19. More than one definition with the same name can exist in one vocabulary.  The 
  20. latter is called a redefinition.  The most recently created redefinition will be 
  21. found when the vocabulary is searched.  
  22. <p>
  23. The most important vocabulary is  <code><A href="_smal_BR#209"> forth </A>.</code> 
  24. The  <code><A href="_smal_BR#209"> forth </A></code> vocabulary contains most of 
  25. the familiar words such as  <code><A href="_smal_BP#1d7"> dup </A>,</code>  <code><A href="_smal_AW#2e6"> swap </A>,</code>  <code><A href="_smal_AT#1c3"> do </A>,</code> 
  26. etc.  Another vocabulary is  <code><A href="_smal_AD#153"> assembler </A>,</code> 
  27. containing words used to assemble machine code.  
  28. <p>
  29. When the Forth interpreter receives a word, either one that you have typed at 
  30. the keyboard or one that it gets from a file, it will look for that word in 
  31. several vocabularies.  The ordered list of vocabularies to search is called the 
  32. "search order".  A word will not be found unless it is contained in one of the 
  33. vocabularies in the search order.  The search order may be changed at any time.  
  34. <p>
  35. To display the search order, use  <code><A href="_smal_BE#28c"> order </A>.</code> 
  36. Example: 
  37. <p>
  38. <br><code>                 order</code><br>
  39. <br><code>                 context: forth forth root       current: forth</code><br>
  40. <p>
  41. In this example, the search order is  <code><A href="_smal_BR#209"> forth </A></code>  <code><A href="_smal_BR#209"> forth </A></code>  <code><A href="_smal_AX#2b7"> root </A>,</code> 
  42. as shown after the heading "context:".  The "context" search order is the list 
  43. of vocabularies that is searched when the interpreter is deciding what to do 
  44. with at word.  The reason that  <code><A href="_smal_BR#209"> forth </A></code> 
  45. appears twice in the search order will be explained later.  The significance of 
  46. the  <code><A href="_smal_AX#2b7"> root </A></code> vocabulary will also be 
  47. explained later.  
  48. <p>
  49. After the heading "current:", the "compilation vocabulary" is shown.  The 
  50. "compilation vocabulary", also called the "current" vocabulary, is the 
  51. vocabulary where newly-created definitions appear.  The compilation vocabulary 
  52. need not be the same as one of the vocabularies in the search order, although in 
  53. practice it usually is.  
  54. <p>
  55. <p>
  56. <h2>Setting the Search Order</h2>
  57. <p>
  58. When a vocabulary is executed, it replaces the first vocabulary in the search 
  59. order.  Note the effect of this sequence of commands: 
  60. <p>
  61. <br><code>                 order</code><br>
  62. <br><code>                 context: forth forth root     current: forth</code><br>
  63. <br><code>                 assembler order</code><br>
  64. <br><code>                 context: assembler forth root     current: forth</code><br>
  65. <p>
  66. See how the execution of  <code><A href="_smal_AD#153"> assembler </A></code> 
  67. replaced the first vocabulary.  
  68. <p>
  69. If you want to add vocabularies to the search order, use the word  <code><A href="_smal_BU#14c"> also </A>.</code>  <code><A href="_smal_BU#14c"> also </A></code> 
  70. duplicates the first entry in the search order, thus making the search order 
  71. contain one more vocabulary.  Continuing with our example, if we now execute: 
  72. <p>
  73. <br><code>                 also  order</code><br>
  74. <br><code>                 context: assembler assembler forth root     current: forth</code><br>
  75. <p>
  76. Notice that the search order now contains 4 vocabularies instead of 3, and that 
  77. the  <code><A href="_smal_AD#153"> assembler </A></code> vocabulary appears 
  78. twice.  It is okay to have a vocabulary listed twice in the search order.  The 
  79. Forth word  <code><A href="_smal_BK#202"> find </A>,</code> which uses the 
  80. search order to search through several vocabularies, is smart enough to 
  81. recognise the duplication and to avoid the wasted effort of searching that 
  82. vocabulary twice.  
  83. <p>
  84. If we execute another vocabulary now, it will replace the duplicate  <code><A href="_smal_AD#153"> assembler </A></code> 
  85. entry.  
  86. <p>
  87. <br><code>                 hidden order</code><br>
  88. <br><code>                 context: hidden assembler forth root     current: forth</code><br>
  89. <p>
  90. Don't worry about the significance of the  <code><A href="_smal_AO#21e"> hidden </A></code> 
  91. vocabulary just yet; we will get back to that later.  
  92. <p>
  93. At this point, with the search order being  <code>"<A href="_smal_AO#21e"> hidden </A></code>  <code><A href="_smal_AD#153"> assembler </A></code>  <code><A href="_smal_BR#209"> forth </A></code>  <code><A href="_smal_AX#2b7"> root </A>"</code> 
  94. , whenever you try to execute a word, the interpreter will first look for the 
  95. word in the  <code><A href="_smal_AO#21e"> hidden </A></code> vocabulary.  If it 
  96. doesn't find the word in  <code><A href="_smal_AO#21e"> hidden </A>,</code> next 
  97. it will look in  <code><A href="_smal_AD#153"> assembler </A></code> , then  <code><A href="_smal_BR#209"> forth </A>,</code> 
  98. and finally in  <code><A href="_smal_AX#2b7"> root </A>.</code> Whenever the 
  99. interpreter finds the word, it stops looking.  If it doesn't find the word in 
  100. any of those vocabularies, it checks to see if the word is a number.  If the 
  101. word is a number, the interpreter pushes the number on the stack.  If the word 
  102. is not a number, the interpreter displays a question mark (?) and gives up.  
  103. <p>
  104. Now suppose you want to shorten the search order, instead of adding things to 
  105. it.  The most common way to do this is the word  <code><A href="_smal_BB#289"> only </A>.</code>  <code><A href="_smal_BB#289"> only </A></code> 
  106. shortens the search order all the way, so that it only contains the  <code><A href="_smal_AX#2b7"> root </A></code> 
  107. vocabulary.  
  108. <p>
  109. <br><code>                 only  order</code><br>
  110. <br><code>                 context: root root     current: forth</code><br>
  111. <p>
  112. The  <code><A href="_smal_AX#2b7"> root </A></code> vocabulary contains only a 
  113. very few words, just those words necessary to control the search order.  
  114. <p>
  115. <br><code>                 WORDS</code><br>
  116. <br><code>                 definitions   forth         previous      seal</code><br>
  117. <br><code>                 except        only          also</code><br>
  118. <p>
  119. These are all the words contained in the  <code><A href="_smal_AX#2b7"> root </A></code> 
  120. vocabulary.  As you have probably guessed, the  <code><A href="_smal_AJ#339"> words </A></code> 
  121. command displays the names of all the words in a particular vocabulary.  
  122. Specifically,  <code><A href="_smal_AJ#339"> words </A></code> displays just 
  123. those words in the first vocabulary of the search order.  In this case, we have 
  124. displayed the words in the  <code><A href="_smal_AX#2b7"> root </A></code> 
  125. vocabulary.  
  126. <p>
  127. Once  <code><A href="_smal_BB#289"> only </A></code> has reduced the search 
  128. order to contain just  <code><A href="_smal_AX#2b7"> root </A>,</code> we can 
  129. use  <code><A href="_smal_BU#14c"> also </A></code> and vocabulary names to 
  130. build any search order we want.  
  131. <p>
  132. To summarise what we have seen so far: 
  133. <p>
  134. <p><pre>
  135.         <vocabulary-name>       Makes the specified vocabulary the first
  136.                                 one in the search order, replacing the one
  137.                                 that was previously first.
  138.         order                   Displays the search order.
  139.         also                    Duplicates the first vocabulary in the
  140.                                 search order, increasing the number of
  141.                                 vocabularies in the search order by one.
  142.         only                    Reduces the search order to contain only
  143.                                 the ROOT vocabulary.
  144.         words                   Displays the names of all the words in
  145.                                 the first vocabulary of the search order.
  146. </pre><p>
  147. <p>
  148. <p>
  149. <h2>Compilation vocabulary</h2>
  150. <p>
  151. Now back to the compilation vocabulary, the one displayed after the "current:" 
  152. heading.  Whenever you define a new Forth word, for instance a colon (:) 
  153. definition or a  <code><A href="_smal_BN#325"> variable </A>,</code> the new 
  154. word is entered into the compilation vocabulary.  The compilation vocabulary may 
  155. be changed with  <code><A href="_smal_AH#1b7"> definitions </A>.</code>  <code><A href="_smal_AH#1b7"> definitions </A></code> 
  156. changes the compilation vocabulary to be the same as the first vocabulary in the 
  157. search order.  
  158. <p>
  159. <br><code>                 order</code><br>
  160. <br><code>                 context: root root     current: forth</code><br>
  161. <br><code>                 definitions</code><br>
  162. <br><code>                 context: root root     current: root</code><br>
  163. <p>
  164. Now new definitions will be entered into the  <code><A href="_smal_AX#2b7"> root </A></code> 
  165. vocabulary, as indicated by "current: root".  You probably won't need to put any 
  166. new definitions in the  <code><A href="_smal_AX#2b7"> root </A></code> 
  167. vocabulary, but you could if you wanted to.  
  168. <p>
  169. Let's get back to a more reasonable search order; right now the only vocabulary 
  170. in the search order is  <code><A href="_smal_AX#2b7"> root </A>,</code> which 
  171. doesn't contain very many interesting words.  
  172. <p>
  173. <br><code>                 forth also order</code><br>
  174. <br><code>                 context: forth forth root     current: root</code><br>
  175. <p>
  176. It's frequently a good idea to execute  <code><A href="_smal_BU#14c"> also </A></code> 
  177. after  <code><A href="_smal_BR#209"> forth </A>,</code> so that the next 
  178. vocabulary won't totally remove  <code><A href="_smal_BR#209"> forth </A></code> 
  179. from the search order.  Most of the time, you want  <code><A href="_smal_BR#209"> forth </A></code> 
  180. to stay in the search order because  <code><A href="_smal_BR#209"> forth </A></code> 
  181. contains most of the basic words that you use a lot.  
  182. <p>
  183. We are still not quite in a normal state, because the compilation vocabulary is  <code><A href="_smal_AX#2b7"> root </A>,</code> 
  184. which is generally not a popular place for new words.  To get into the normal 
  185. state, we need: 
  186. <p>
  187. <br><code>                 definitions  order</code><br>
  188. <br><code>                 context: forth forth root     current: forth</code><br>
  189. <p>
  190. Now we are back to the situation that prevails when Forth is first started.  We 
  191. got there by a tedious route, one step at a time, looking at the search order 
  192. after nearly every step.  The easy way to get there is to execute this phrase: 
  193. <p>
  194. <br><code>                 only forth also definitions</code><br>
  195. <p>
  196. This is a very commonly-used phrase.  It gets you back to the "normal" search 
  197. order after you have been mucking around with the search order for some reason 
  198. or another.  It is important to understand how this works; if it isn't clear to 
  199. you, reread this chapter, then try executing the phrase one word at a time, 
  200. executing  <code><A href="_smal_BE#28c"> order </A></code> after each word.  
  201. <p>
  202. <p>
  203. <h2>Creating New Vocabularies</h2>
  204. <p>
  205. So far we have been using vocabularies that are already in the Forth system.  
  206. You can make your own vocabularies too.  But first, lets get a list of all the 
  207. vocabularies already in the system.  
  208. <p>
  209. <br><code>                 vocs</code><br>
  210. <br><code>              bug ignoredom command-completion keys-forth terminals</code><br>
  211. <br><code>                 system assembler hidden root forth</code><br>
  212. <p>
  213. Note the distinction between the search order, which is the list of vocabularies 
  214. that are being searched, and the list displayed by  <code><A href="_smal_BS#32a"> vocs </A>.</code>  <code><A href="_smal_BS#32a"> vocs </A></code> 
  215. displays the names of ALL vocabularies, regardless of whether or not they are in 
  216. the search order right now.  
  217. <p>
  218. We have seen some of these vocabularies before.  Later, I will tell you more 
  219. about the other ones, but for now let's make a new one.  
  220. <p>
  221. <br><code>                 order</code><br>
  222. <br><code>                 context: forth forth root    current: forth</code><br>
  223. <br><code>                 vocabulary myvoc</code><br>
  224. <br><code>                 order</code><br>
  225. <br><code>                 context: forth forth root    current: forth</code><br>
  226. <br><code>                 vocs</code><br>
  227. <br><code>                 myvoc ignoredom command-completion keys-forth disassembler</code><br>
  228. <br><code>                 system assembler hidden root forth</code><br>
  229. <p>
  230. Notice that the creation of the new vocabulary did  <code><A href="_smal_AM#27c"> not </A></code> 
  231. change the search order.  When a vocabulary is created, it is not automatically 
  232. added to the search order.  It does, however, now appear in the list of all 
  233. vocabularies as displayed by  <code><A href="_smal_BS#32a"> vocs </A>.</code> 
  234. How do we get the new vocabulary into the search order? Just execute it, of 
  235. course.  
  236. <p>
  237. <br><code>                 myvoc order</code><br>
  238. <br><code>                 context: myvoc forth root    current: forth</code><br>
  239. <p>
  240. What's in the new vocabulary? Exactly what we have put into it: nothing.  
  241. <p>
  242. <br><code>                 words</code><br>
  243. <p>
  244. Since our new vocabulary is the first thing in the search order,  <code><A href="_smal_AJ#339"> words </A></code> 
  245. displays the words in <strong>myvoc</strong> , and since we haven't put any 
  246. words in it, there are none to display.  
  247. <p>
  248. To put some new words into <strong>myvoc</strong> , we have to make <strong>myvoc</strong> 
  249. the compilation vocabulary.  
  250. <p>
  251. <br><code>                 definitions  order</code><br>
  252. <br><code>                 context: myvoc forth root     current: myvoc</code><br>
  253. <p>
  254. Now any new words we define will go into <strong>myvoc</strong> .  Let's make 
  255. one: 
  256. <p>
  257. <br><code>                 : SSS ." hello" ;</code><br>
  258. <p>
  259. It does not really matter what words you make, we are only interested in seeing 
  260. where they appear.  
  261. <p>
  262. <br><code>                 words</code><br>
  263. <br><code>                 sss</code><br>
  264. <p>
  265. Now we can execute <strong>sss</strong> , because it is contained in the 
  266. vocabulary <strong>myvoc</strong> , which is in the search order.  
  267. <p>
  268. <br><code>                 sss</code><br>
  269. <br><code>                 hello</code><br>
  270. <p>
  271. But suppose <strong>myvoc</strong> were not in the search order? Let's replace <strong>myvoc</strong> 
  272. in the search order with  <code><A href="_smal_BR#209"> forth </A>.</code> 
  273. <p>
  274. <br><code>                 order</code><br>
  275. <br><code>                 context: myvoc forth root     current: myvoc</code><br>
  276. <br><code>                 forth  order</code><br>
  277. <br><code>                 context: forth forth root     current: myvoc</code><br>
  278. <br><code>                 sss</code><br>
  279. <br><code>                 sss ?</code><br>
  280. <p>
  281. This time, <strong>sss</strong> didn't work, because the vocabulary where it 
  282. lives is no longer in the search order.  Notice that myvoc is still the 
  283. compilation vocabulary, (the word to change the compilation vocabulary is  <code><A href="_smal_AH#1b7"> definitions </A>,</code> 
  284. and we haven't executed that recently).  Having <strong>myvoc</strong> as the 
  285. compilation vocabulary doesn't help us find <strong>sss</strong> , because the 
  286. thing that controls whether or not a word is found is the search order.  The 
  287. compilation vocabulary just controls where to put new words.  
  288. <p>
  289. <p>
  290. <h2>More Search Order Words</h2>
  291. <p>
  292. There are a few more words to control the search order.  They generally aren't 
  293. used nearly as often as the ones we have seen so far.  The first is  <code><A href="_smal_BU#29c"> previous </A>,</code> 
  294. which is sort of like the opposite of  <code><A href="_smal_BU#14c"> also </A>.</code> 
  295. Whereas  <code><A href="_smal_BU#14c"> also </A></code> increases the number of 
  296. vocabularies in the search order by duplicating the first one,  <code><A href="_smal_BU#29c"> previous </A></code> 
  297. reduces the number by tossing out the first one.  
  298. <p>
  299. <br><code>                 only forth also definitions order</code><br>
  300. <br><code>                 context: forth forth root    current: forth</code><br>
  301. <br><code>                 previous order</code><br>
  302. <br><code>                 context: forth root    current: forth</code><br>
  303. <p>
  304.  <code><A href="_smal_BU#29c"> previous </A></code> need not follow  <code><A href="_smal_BU#14c"> also </A></code> 
  305. ; it will happily throw out the first vocabulary in the search order even if 
  306. that vocabulary is not duplicated in the search order.   <code><A href="_smal_BU#29c"> previous </A></code> 
  307. is not a part of the Forth 83 Standard, but it is in the popular F83 Forth 
  308. implementation.   <code><A href="_smal_BU#29c"> previous </A></code> is not 
  309. frequently used in most code that I have seen.  Most people prefer to rebuild 
  310. the search order from scratch with  <code><A href="_smal_BB#289"> only </A></code> 
  311. and  <code><A href="_smal_BU#14c"> also </A>,</code> rather than trying to keep 
  312. track of adding and removing vocabularies from the search order.  
  313. <p>
  314. Another search order tool is  <code><A href="_smal_AN#1ed"> except </A>.</code>  <code><A href="_smal_AN#1ed"> except </A></code> 
  315. takes an argument from the input stream, which is the name of a vocabulary to 
  316. remove from the search order.  
  317. <p>
  318. <br><code>                 only forth hidden also forth also  order</code><br>
  319. <br><code>                 context: forth forth hidden root     current: forth</code><br>
  320. <br><code>                 except hidden  order</code><br>
  321. <br><code>                 context: forth forth root     current: forth</code><br>
  322. <p>
  323.  <code><A href="_smal_AN#1ed"> except </A></code> will go through the search 
  324. order and remove any occurrence of the vocabulary which is its argument  <code>(<A href="_smal_AO#21e"> hidden </A></code> 
  325. in this case).   <code><A href="_smal_AN#1ed"> except </A></code> is unique to 
  326. Forthmacs; I don't know of any other Forth that has it.  
  327. <p>
  328. Finally, there is the standard word  <code><A href="_smal_BR#2c9"> seal </A>.</code>  <code><A href="_smal_BR#2c9"> seal </A></code> 
  329. removes all occurrences of  <code><A href="_smal_AX#2b7"> root </A></code> from 
  330. the search order.  You may have noticed that  <code><A href="_smal_AX#2b7"> root </A></code> 
  331. tends to remain in the search order no matter what you do; well,  <code><A href="_smal_BR#2c9"> seal </A></code> 
  332. is the way to get rid of it.  You will hardly ever want to do this.  It does 
  333. come in handy for implementing "turnkey" systems, where the user is not supposed 
  334. to have access to any Forth words other than the ones that you explicitly 
  335. provide.  With  <code><A href="_smal_AX#2b7"> root </A></code> removed from the 
  336. search order, you can make it impossible to change the search order.  For 
  337. example (don't try this or you will have to restart Forth): 
  338. <p>
  339. <br><code>                 only forth myvoc seal</code><br>
  340. <p>
  341. Right before  <code><A href="_smal_BR#2c9"> seal </A></code> is executed, the 
  342. search order is: 
  343. <p>
  344. <br><code>                 context: myvoc root     current: forth</code><br>
  345. <p>
  346. Right after, the search order is: 
  347. <p>
  348. <br><code>                 context: myvoc     current: forth</code><br>
  349. <p>
  350. Since <strong>myvoc</strong> does not contain any words which modify the search 
  351. order, there is no way to get out.  
  352. <p>
  353. <p>
  354. <h2>Predefined Vocabularies</h2>
  355. <p>
  356. Risc-OS Forthmacs contains several built-in vocabularies.  We saw their names 
  357. when we executed  <code><A href="_smal_BS#32a"> vocs </A>.</code> To get a list 
  358. of the words in a vocabulary, put that vocabulary in the search order by typing 
  359. its name, then execute  <code><A href="_smal_AJ#339"> words </A>.</code> Here 
  360. are the Risc-OS Forthmacs vocabularies and their contents: 
  361. <p>
  362. <p><pre>
  363.         root                    Contains words used to control the search
  364.                                 order.  Selected by executing ONLY.
  365.         forth                   Contains most of the important words.
  366.                                 This is the most important vocabulary.
  367.         hidden                  Contains a lot of words which help to
  368.                                 implement other words.  The words in
  369.                                 HIDDEN are not intended for use by
  370.                                 applications programs, because they are
  371.                                 not documented and not guaranteed to remain
  372.                                 the same or even exist in future releases.
  373.                                 If the decompiler shows a word that is not
  374.                                 in the FORTH vocabulary, this is a good
  375.                                 place to look.
  376.         assembler               Contains words for assembling machine
  377.                                 code.  See the "Assembler" chapter.
  378.         system                  Contains words which are direct interfaces
  379.                                 to certain TOS system calls.  See the
  380.                                 "System Calls" chapter.
  381.         disassembler            Contains words used to implement the
  382.                                 disassembler.
  383.         keys-forth              Contains words which associate keystrokes
  384.                                 with the editing functions of the command
  385.                                 line editor.  The command line editor
  386.                                 searches KEYS-FORTH directly, without
  387.                                 using the search order.  You can change
  388.                                 the keys used by the command line editor
  389.                                 by redefining the words in this
  390.                                 vocabulary.
  391.         bug                     Contains words needed for the assembler level
  392.                                 debugger or other debugging tools.
  393. </pre><p>
  394. <p>
  395. <p><pre>
  396.         command-completion      Contains words used to implement the
  397.                                 command completion feature of the command
  398.                                 line editor.
  399.         ignoredom               Gee, I liked this name when I thought it
  400.                                 up.  It seems pretty awful now.  Anyway,
  401.                                 IGNOREDOM contains words used to
  402.                                 implement the condition compilation words
  403.                                 IFTRUE, OTHERWISE, IFEND, etc.
  404. </pre><p>
  405. <p>
  406. <p><pre>
  407.         TERMINALS               Contains words used to describe the
  408.                                 characteristics of various types of
  409.                                 terminals which can be connected to the
  410.                                 system.
  411. </pre><p>
  412. <p>
  413. <p>
  414. <h2>One More Thing</h2>
  415. <p>
  416. When you started a colon definition in elderly Risc-OS Forthmacs versions or 
  417. other Forth-83 implementations, the first vocabulary in the search order was 
  418. changed to be the same as the compilation vocabulary.  For example: 
  419. <p>
  420. <br><code>                 only forth also hidden definitions  forth order</code><br>
  421. <br><code>                 context: forth forth root     current: hidden</code><br>
  422. <br><code>                 : qqq  [ order ]</code><br>
  423. <br><code>                 context: hidden forth root     current: hidden</code><br>
  424. <br><code>                 ;</code><br>
  425. <br><code>                 order</code><br>
  426. <br><code>                 context: hidden forth root     current: hidden</code><br>
  427. <p>
  428. See how the first vocabulary in the search order changed from  <code><A href="_smal_BR#209"> forth </A></code> 
  429. to  <code><A href="_smal_AO#21e"> hidden </A>.</code> This behavior is built in 
  430. to : so that the compilation vocabulary will be part of the search order while 
  431. the colon definition is being completed.  
  432. <p>
  433. Note that the original search order is  <code><A href="_smal_AM#27c"> not </A></code> 
  434. restored after the colon definition is finished.  Thus a colon definition can 
  435. alter the search order.  Usually this is not a problem, because most of the time 
  436. the compilation vocabulary is the first one in the search order anyway.  But 
  437. don't say I didn't warn you.  
  438. <p>
  439. <strong>This is not the case in current Forthmacs or ANS Forth versions.</strong> 
  440. The search order is  <code><A href="_smal_AM#27c"> not </A></code> changed by 
  441. colon any longer!) 
  442. <p>
  443. <p>
  444. Code definitions do a funny thing too: 
  445. <p>
  446. <br><code>                 only forth also hidden definitions  forth order</code><br>
  447. <br><code>                 context: forth forth root     current: hidden</code><br>
  448. <br><code>                 code rrr   order</code><br>
  449. <br><code>                 context: assembler forth root     current: hidden</code><br>
  450. <p>
  451. First, note that the first vocabulary in the search order is  <code><A href="_smal_AD#153"> assembler </A>,</code> 
  452. not  <code><A href="_smal_BR#209"> forth </A></code> or  <code><A href="_smal_AO#21e"> hidden </A>.</code> 
  453. Second, note that I did not have to put brackets ([ ]) around  <code><A href="_smal_BE#28c"> order </A></code> 
  454. this time, because code definitions are not created in compile state like colon 
  455. definitions.  If fact, if I had used brackets, it wouldn't have worked right, 
  456. because the closing bracket (]) would have thrown me into compile state which is 
  457. not what I want.  
  458. <p>
  459. Now watch what happens when I finish the code definition: 
  460. <p>
  461. <br><code>                 end-code</code><br>
  462. <br><code>                 order</code><br>
  463. <br><code>                 context: hidden forth root     current: hidden</code><br>
  464. <p>
  465. Weird, huh? Why did it restore the first vocabulary to  <code><A href="_smal_AO#21e"> hidden </A>,</code> 
  466. instead of back to  <code><A href="_smal_BR#209"> forth </A>?</code> It is 
  467. reasonable to restore it to something other than  <code><A href="_smal_AD#153"> assembler </A>,</code> 
  468. something, because you hardly ever want the  <code><A href="_smal_AD#153"> assembler </A></code> 
  469. vocabulary in the search path except when you are actually in the middle of 
  470. assembling something.  The question is, what do you restore it to? The 
  471. reasonable answer is to restore it to its previous state, but that is not the 
  472. way it works.  For historical reasons,  <code><A href="_smal_BV#1dd"> end-code </A></code> 
  473. restores the first vocabulary in the search path to the compilation vocabulary.  
  474. Since the compilation vocabulary is usually the same as that first vocabulary in 
  475. the search path, this does the right thing most of the time.  It is only a 
  476. problem if you don't know about it.  
  477. <p>
  478. </body>
  479. </html>
  480.