![]() |
You. Forth. Simplicity. |
reload node | edit | recent changes | front page
Another important aspect is the scoping abilities provided by the Rx Core. The lexical scope constructs allow a good deal of control over how you can factor and what is made visible to the dictionary. By using the words loc: and ;loc you can create lexically scoped regions of code and then use alias or is to expose specific definitions in these regions. A simple example of their use would look like:
loc:
10 constant ten
20 constant twenty
10 20 * constant two-hundred
:: two-hundred ;
;loc is value
When a lexically scoped region is closed with ;loc, the word headers up to the previous loc: are dropped from the dictionary. You can use anonymous definitions with alias or is to expose what is needed. Also (not shown in the example), you can nest lexically scoped sequences. Nesting is possible up to four levels deep. Lexical scopes are used frequently by the developers of Rx and allow a good level of factoring without polluting the actual dictionary with words that are not needed outside a select few definitions.