On 12/10/11 4:34 PM, Arnold Doray wrote:
> On Sat, 10 Dec 2011 23:03:46 +0100, Bernd Paysan wrote:
>
...
No. The fact that the system is in compilation state influences what the
text interpreter will do when it runs, but doesn't immediately launch
it. The text interpreter won't become active until TEST finishes executing.
I can write a word like this:
: mycolon : here . 100 0 do i . loop cr ." Hello world" ;
...and if I then say:
mycolon foo ." Goodbye cruel world" ;
...then foo will compile perfectly normally, but a whole bunch of stuff
will happen before the actual compilation commences.
> As an analogy, the words [ and ] immediately switch the forth between
> interpretative and compilation states. So I thought once you're in
> compilation state, the text-parser should be doing its thing immediately.
>
> Do you see?
I see that you have a mistaken impression of how the text interpreter
works. It operates *either* when you explicitly invoke it with a word
that parses *or* when everything that is executing is done and control
passes to the text interpreter to process the input stream. :noname
does not invoke the text interpreter explicitly. : does, but only long
enough to get the name of the definition to be created.
> I'm saying it is non-intuitive if the text-parser does not kick in
> immediately after :NONAME executes. The system is already in compilation
> state.
>
> The forths I have tested are effectively behaving as if the text-parser
> starts after the TEST executes. Why then? This seems arbitrary to me and
> not at all a sensible choice.
That is exactly the way it works and the way it's described in, for
example, the flow-chart in my books that describes the text interpreter.
>> IIRC, PolyForth had it the way you expect it - : and ] just started
>> another parsing loop, but this eliminates some possibilities. E.g. I
>> can write CONSTANT without CREATE DOES> that way:
>>
>> : Constant>r : r> postpone literal postpone ; ;
>>
>> This is a nice capability.
It drove people nuts. Suppose you typed:
: foo ( -- ) doors 0 do
...and then thought to yourself, wait a minute, what's the value of
doors again? So you type:
doors .
...You will then be very confused because the system just says, "ok"
without executing doors and . because what has happened is that the
compiler kept right on compiling the definition foo including a
reference to doors and . and is still compiling, and will continue until
you type ; or an error occurs.
It seemed nice at the time, but caused a lot of trouble.
> Really? I don't think modern forths use CREATE DOES> to define constants.
They can, and many do:
: CONSTANT ( n -- ) CREATE , DOES> ( -- n ) @ ;
> Also, doesn't your example rely on return stack fiddling which I
> understand is not portable?
I'm not wild about that example, myself.
> I would prefer a sensible :NONAME. You can do a lot with it. Portably.
It is intended to be, and is, exactly like : without a name for the
compiled code. Why don't you tell us what you're trying to do, and maybe
we can help find a way to do it?