I was messing around and trying to understand it, so I wrote a simple word to test it:
: test ." compile time" DOES> ." runtime" ;
The problem is, this word doesn't behave in a consistent way at all. Its output seems to vary depending on a number of factors, like:
- is this the first line to be interpreted?
- are there other words defined after it?
Also, sometimes it doesn't print anything at all.
(Using Gforth)
Interactive play
In Gforth you can play with
does>
interpretively.So
does>
just changes behavior of the last word, when this last word is defined viacreate
. It's a mistake if you rundoes>
when the last word was not defined viacreate
.Usage in practice
Usually
does>
is used to set a new behavior only once for a word defined viacreate
. An ability to alter this behavior several times it just a side effect of historical implementation, and this effect is almost not used in the practice.Alternative ways
In practice, the cases when
does>
is used, can be also implemented withoutdoes>
.For example, let we want to implement a word
counter
that creates a counter that every time returns the next value, and that is used in the following way:An implementation via
create
does>
An implementation using a quotation
An implementation using a macro (code inlining) via the word
]]
: