Interactive mode with new words

75 views
Skip to first unread message

David Meyer

unread,
Nov 23, 2018, 5:46:29 AM11/23/18
to 4tH-compiler
Thanks for working on and making available 4tH.

I understand that unlike many other Forth implementations, 4tH's interactive mode does not support word-defining words (": newword ... ;") and that such code has top be stored in a file or block and compiled. But is it possible to make compiled words available in an interactive 4tH session? 

In another Forth implementation I wrote some word definitions intended to be used along with other Forth words in calculator mode. The user starts the interactive session, loads the word definition file (or puts it in the run commands file to load automatically), and can then use my words the same as build-in +, -, dup, etc.

thebeez

unread,
Nov 23, 2018, 6:08:28 AM11/23/18
to 4th-co...@googlegroups.com
Hi David!

Thanks for using 4tH. Actually, your question is in the FAQ.

QUESTION: When I open up the editor in 4tH, it takes most 4tH code like
an actual
Forth compiler, but not my colon definitions. Why?

ANSWER: The 4tH editor mimics Forth, that’s true. But it is actually a
Forth like
environment on top of 4tH. It may seem like you’re working on a Forth
prompt, but you’re not. You can use the editor only for editing or some
quick calculations, but if you want to use the full capability of 4tH,
you’re
stuck to the menu.

In other words, the editor does a good job of faking it is an
interactive Forth - but it isn't. It's just an editor with some
calculation capabilities. There is not even remotely such a thing as a
compiler there. The point is, unlike other Forths, 4tH compiles straight
away to an image. 4tH doesn't have a dictionary. When compiling it
builds a symboltable that is thrown away right after (although in the
upcoming version 3.63, it can be kept for a limited number of purposes).

I know it's hard to wrap your head around if you know other Forths, but
may be this page helps:

https://sourceforge.net/p/forth-4th/wiki/Short%20review/

Hans Bezemer

David Meyer

unread,
Nov 23, 2018, 11:30:25 AM11/23/18
to 4tH-compiler
That's interesting. I see what you're saying. It is quite different from other Forth implementations. So basically 4tH always produces a stand-alone program. I wonder if I could program a fully interactive 4tH shell. ;)


thebeez

unread,
Nov 28, 2018, 7:18:01 AM11/28/18
to 4th-co...@googlegroups.com
Yes, you're right: it's quite different. However, I found that with the
preprocessor you can "translate" a lot of the "execute at compiletime"
functionality. Since I wrote a BASIC interpreter in 4tH I think an
attempt to write an interpretive version of 4tH (read: classic Forth) in
4tH is quite feasible - but a lot of work.

Lots of typical 4tH constructs can be written in Forth, as I've proven
with the Easy4tH interface. Some though, like :TOKEN or TAG, are much
harder.

Hans Bezemer
Reply all
Reply to author
Forward
0 new messages