interpretation mode why? 
Author Message
 interpretation mode why?

When speaking of self-targetting Forth's (i.e. not cross-compilers)
...

When speaking of words whose interpretation semantics Ans Forth
bothers to define ...

Is compiling the word and executing what compiles ever a bad way of
getting an idea of what the word does?

For example, if I want to know what:

        1 1 tuck + .s
        tuck + .s
        tuck + .s

does, I appreciate I can enter those three lines, but my question is,
can I not instead enter:

        : once
        ; once : once 1 1 tuck + .s
        ; once : once tuck + .s
        ; once : once tuck + .s

?

When will this kind of elaboration lead me astray?

Supposing my Forth gives me a way of restoring the dictionary memory I
may leak by redefining once repeatedly, what else do I lose by never
executing any word in interpretation mode?


state-smart words.  An imperceptible loss?

I see I'd need to teach the : word to enter the ( ; once ) and the ( :
once ) for me.  For example, I'd need:

        ; once : once : fib tuck + ;

to mean:

        ; once : once ; once : fib tuck + ; : once

When will this kind of elaboration lead me astray?

Thanks in advance.    Pat LaVarre



Sat, 13 Mar 2004 08:31:29 GMT  
 interpretation mode why?

Quote:
>When speaking of self-targetting Forth's (i.e. not cross-compilers)
>...
>When speaking of words whose interpretation semantics Ans Forth
>bothers to define ...
>Is compiling the word and executing what compiles ever a bad way of
>getting an idea of what the word does?

Yes, when it does different things compiling and interpreting.  Not
many do.  One that does is S" which in its base definition is a
compiler word for compiling a string that leaves a ( ... -- ... ca u )
to the string on the stack when the word executes, and in its
interpretation mode extension is an interpretor word for stuffing the
text up to " into a buffer and then leaving a ( -- ca u ) to the
string on the stack.

Difference? You can compile as many different S" ..." strings as you
wish, and they are all unique.  Use S" ..." twice in a row in the
interpreter, and the buffer is overwritten, even though you may still
have an obsolete reference to the first string on the stack.

There are not many times that ANS overloads two different words into
the same name like that.

(
----------
Virtually,

Bruce McFarling, Newcastle,

)



Sat, 13 Mar 2004 11:59:27 GMT  
 interpretation mode why?

Quote:

>Yes, when it does different things compiling and interpreting.  Not
>many do.  One that does is S" which in its base definition is a

I understood the original question as asking, "Is there any distinct
advantage to having a distinct interpret- and compile-modes of
operation?", and, "Is it technically possible to create a Forth environment
that first compiles interactive input, then executes it?"

--
KC5TJA/6, DM13, QRP-L #1447
Samuel A. Falvo II
Oceanside, CA



Sat, 13 Mar 2004 15:40:28 GMT  
 interpretation mode why?

Quote:

> Is compiling the word and executing what compiles ever a bad way of
> getting an idea of what the word does?

no

Quote:

> For example, if I want to know what:

>         1 1 tuck + .s
>         tuck + .s
>         tuck + .s

> does, I appreciate I can enter those three lines, but my question is,
> can I not instead enter:

>         : once
>         ; once : once 1 1 tuck + .s
>         ; once : once tuck + .s
>         ; once : once tuck + .s
          ; once

> ?

you can

[..]

Quote:
> what else do I lose by never
> executing any word in interpretation mode?

Defining words ( : CREATE VARIABLE VALUE DEFER etc)
should be invoked in interpretation state.

' DUP could give an unexpected result.
(two copies of xt of name that follows "once" in the input stream;
this is so because tick "'" gets compiled, and DUP also gets compiled.)

It is possible to write a Forth system that uses the states
1) compilation to the tempoorary buffer
2) cmpilation to a definition
instead of
1) interpretation
2) compilation
but this system will not be compatible with the traditional approach.

IMO, testing via interactive compilation to a scratch buffer is not
worse than testing in interpretation state -- provided that you
care to avoid "stepping on a rake".

--
the right question is half the answer



Sat, 13 Mar 2004 16:05:05 GMT  
 interpretation mode why?


Quote:

>>Yes, when it does different things compiling and interpreting.  Not
>>many do.  One that does is S" which in its base definition is a

>I understood the original question as asking, "Is there any distinct
>advantage to having a distinct interpret- and compile-modes of
>operation?", and, "Is it technically possible to create a Forth environment
>that first compiles interactive input, then executes it?"

Aha, I understood it as asking, about ANS Forth, "Is compiling the
word and executing what compiles ever a bad way of getting an idea of
what the word does?"  And it sometimes is ... not often, but
sometimes.  Its a quite well posed question, since those cases are
exactly where you would need two distinct modes if you compiled
everything: mode "I am compiling but pretending to be in interpret
mode", and mode "I am actually compiling".

(
----------
Virtually,

Bruce McFarling, Newcastle,

)



Sat, 13 Mar 2004 16:27:42 GMT  
 interpretation mode why?

Quote:


> >When speaking of self-targetting Forth's (i.e. not cross-compilers)
> >...

> >When speaking of words whose interpretation semantics Ans Forth
> >bothers to define ...

> >Is compiling the word and executing what compiles ever a bad way of
> >getting an idea of what the word does?

> Yes, when it does different things compiling and interpreting.  Not
> many do.  One that does is S" which in its base definition is a
> compiler word for compiling a string that leaves a ( ... -- ... ca u )
> to the string on the stack when the word executes, and in its
> interpretation mode extension is an interpretor word for stuffing the
> text up to " into a buffer and then leaving a ( -- ca u ) to the
> string on the stack.

> Difference? You can compile as many different S" ..." strings as you
> wish, and they are all unique.  Use S" ..." twice in a row in the
> interpreter, and the buffer is overwritten, even though you may still
> have an obsolete reference to the first string on the stack.

> There are not many times that ANS overloads two different words into
> the same name like that.

        That's more or less the reason why I wanted to suppress the
interpretation state in 4IM (Cat-tree-M -- see FIFTH?! article): the
aim to is to eliminate this kind of question; and words such as IF
THEN... become accessible from "interpretation" state and behave
always the same.
        However I had to reintroduce the "immediate word" concept to make it
work: immediate words are grouped in a vocabulary that make them
immediate. I don't find thsi solution very elegant. 4IM has a
mechanism that allows to extend the compiler by letting other words to
try to parse ans compile the input stream when a dictionnary search
fails. Number,string and comments are translated this way (Thus 4Im
doesn't know the double quote word, nor requires a space after a left
parenthesis). Now I think I'll put immediate words in this mechanism,
because it is not abusive to say that they are parts of the compiler.


Sat, 13 Mar 2004 19:30:14 GMT  
 interpretation mode why?

Quote:

>  ...  (Thus 4Im
> doesn't   ... nor require[s] a space after a left
> parenthesis)...

If '(' isn't a space-delimited word like the rest of Forth, it would seem
that you couldn't define, say, (WORD . Is that correct?

Jerry
--
Engineering is the art of making what you want from things you can get.
-----------------------------------------------------------------------



Sat, 13 Mar 2004 23:19:04 GMT  
 interpretation mode why?

Quote:


> >  ...  (Thus 4Im
> > doesn't   ... nor require[s] a space after a left
> > parenthesis)...

> If '(' isn't a space-delimited word like the rest of Forth, it would seem
> that you couldn't define, say, (WORD . Is that correct?

> Jerry

Correct, as well as "WORD etc... I don't matter about this, cause I
don't intend to be ANS. But it requires to be careful about the
equivalent of the search order.


Sun, 14 Mar 2004 19:41:12 GMT  
 interpretation mode why?


Quote:
>For example, if I want to know what:

>    1 1 tuck + .s
>    tuck + .s
>    tuck + .s

>does, I appreciate I can enter those three lines, but my question is,
>can I not instead enter:

>        : once
>        ; once : once 1 1 tuck + .s
>        ; once : once tuck + .s
>        ; once : once tuck + .s

>?

>When will this kind of elaboration lead me astray?

When the code contains a parsing word, like '.

When the code contains a word with different interpretation and
compilation semantics, even if these semantics are designed to be
similar, like S".

: foo s" one" s" two" type type ; foo

gives a different result on some systems (e.g., Gforth) from

s" one" s" two" type type

BTW, related to this question, I have added the following question and
answer to the General/Misc FAQ:

  5.10.  How about interpreting by compiling and immediately executing?

  Such ideas have been proposed several times, to allow using control
  structures interpretively, among other benefits.  It has also been
  implemented in some systems (e.g., Christophe Lavarenne's Free-Forth).
  In most proposals a line would be compiled and then executed.

  However, such systems behave quite differently from ordinary Forth
  systems in some respects, in particular when dealing with parsing
  words.  E.g., consider:

  ______________________________________________________________________
   ' + .
  : my-' ' ;
  my-' + .
  ______________________________________________________________________

  In classical Forth ' parses + in both cases.  This behaviour is hard
  to achieve in a compile-then-execute Forth system, unless it works a
  word at a time, but then it would have none of the benefits, either.

- anton
--
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html



Wed, 17 Mar 2004 17:55:04 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. why why why oh why why baby

2. mode (or why BASIC-like thinking is not enough)

3. Why Protected Mode???

4. Tclvfs: why no r+ file open mode?

5. Why make libtcl7.6.so mode 555?

6. Why, Why Why????

7. why why why (mouse related question)

8. Real mode & Protected mode - Why, when ?

9. Array Oriented interpretation of Classical Algorithms

10. Error Message Interpretation Urgent!!!

11. Compilation vs. Interpretation

12. Compilation vs Interpretation

 

 
Powered by phpBB® Forum Software