| Re: Visibility inside a colon definition |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.forth · Group Profile
Author: helmwohelmwo Date: Jan 12, 2008 03:47
On Jan 11, 6:19Â pm, Brad Eckert tinyboot.com> wrote:
> I notice that colorForth doesn't hide the name of the definition
> currently being defined. That means you can't do something like:
>
> : foo ." Hello" ;
> : foo foo ." Â World" ;
>
> I'm not sure, but I think if you use the name of the word being
> compiled, it compiles as a jump to the beginning of the word, not a
> call to itself (like RECURSE).
Does not RECURSE also compiles a call? I think so.
> It seems that Chuck may have thought the ability to restart a word
> from the middle of any control structure was more valuable than the
> ability to chain functions together by retaining visibility of the old
> word until ;. I assume that the XT of an old version of the word can
> be placed on the stack before the definition, then compiled into the
> definition with COMPILE so as to have the same chaining functionality.
>
> Does anyone have some example code showing the benefits of the
> colorForth way, or thoughts on the subject?
RetroForth, Reva, HelFORTH, 4p and others use this way too. It's not
only simpler to implement, there is another thing that makes RECURSE a
little bit complicated. I'm from now on refer to 4p and HelFORTH. If
you want to implement a word like RECURSE you've to keep track of the
last colon definition. This is more or less an extra level of
complication that at least I want to avoid. There are for example with
local variables even in ANS ways to define new words inside colon
definitions. In 4p the targets for code, dictionary information and
data are different. This is quite different from say "thumb"
implementations where word names and used data are compiled to the
same place as code. You can create in 4p as much new words as you want
inside colon definitions without affecting the generated code. So a
word like SMUDGE (which you obviously and hiddenly need for ANS and a
correctly working RECURSE) or even RECURSE would have a strange task.
You can see the extra work in my ANS layer. So as I told, you can make
as much new words inside a colon definition as you want - and you can
even make new colon definitions. Therefore my ":" is an IMMEDIATE
word. This should be also one aspect of colorforth - you simply say
where a word starts without thinking in terms of that this word is a
"function" or "subroutine". So you can do in 4p:
: a
." Hello "
: b
if ." C.L.F!"
else ." World! " 1 a
then
;
Where the output is:
0 a
Hello World! Hello C.L.F!
1 a
Hello C.L.F!
You see: what would be the best target for RECURSE?
Well, I personally like RECURSE. So I've implemented it with the
semantics to proceed the last defined word in current dictionary with
4p. That's mainly because I sometimes rename words immediately after
testing (without much code refering to it) and so I'd also have to
rename all RECURSE-replacements, which is a S&R-step in the editor
more.
One drawback of my implementation in 4p is, that outside the ANS-layer
you can not use RECURSE in a useful way in words that have locals...
That where only some thinkings ;) I hope it does not look to
confuse...
Regards,
-Helmar
|