A bit more word related stuff
Before we begin to explore the namespace a (arrays) further, we first need to explain a bit more about words.When we define a word we start with the : (colon word) and end with the ; (semi colon word). 8th will compile the word and after that the word can be invoked by other parts of your code.
We call this kind of words named words, because you give them an explicit name.
Anonymous words
In some cases it is handy to have a word definition without giving that definition a name. For such cases there are anonymous words.Just as the colon and semi colon words begin and end the definition of a named word, the opening and closing parentheses words begin and end an anonymous word, like so:
( “Hi there “ . cr )
Note that these are all 8th words and must be space delimited!
Callback words – words used as parameters for another word
Sometimes an 8th word is needed as a parameter by another word.If you would write down such a helper word right away, things go awry, because then that helper word is being invoked instead of passed as a parameter.
Example 1
- imagine we want to use an arbitrary word x which in turn needs a helper word y during the execution of that word x
- suppose that the SED of word x is \ helperword –
If we now wish to invoke x and do something like this:
y x
the following happens:
- 8th will invoke the word y instead of handing it to x as a parameter
- then x expects a parameter (the word y) to be on the stack, which won’t be the case
But that is not what we want at all! In order to prevent 8th from invoking the word y, we need to tell 8th that it should hand over the definition of y to x.
Especially for such cases there is the ‘ (single quote) word.
Example 2
So now we can invoke x using the helper word y like so:
‘ y x
and everything works well!
Note that the ‘ word must be a plain quote. (Microsoft Word shows it here as a bottom up comma. For code always use a plain tekst editor). The same applies to double quotes.
Anonymous word used as a callback
Because of the nature of anonymous words, you can also define a helper word as mentioned above as an anonymous word.In that case you don’t need to quote the anonymous word.
So now we can invoke x using an anonymous helper word like so:
( “Value = “ . . cr ) x
How to invoke a helper word y from a word x
There is a word called w:exec which can be used to invoke another word.Example
To complete the picture we now create a small program demonstrating the different features we talked about.
We will put a numeric item on the stack and show the result of adding 100 to it.
We do this in 3 different ways. Here is the output:
More info about 8th
Central website for 8th is: http://8th-dev.comYouTube Channel here: https://goo.gl/DscYVD
BLOG here: http://goo.gl/n1NocJ


No comments:
Post a Comment