22

I want to start learning Forth (like in the related Stack Overflow question Is it practical to learn and use Forth?). I see that there are many implementations. I would like to use a

  • ANS 1994 compatible version (if reasonable, but sticking to the standard might be good)
  • small and compact implementation, I don't want a full OS.
  • Windows
  • easy to use, I am new to Forth ;-)

What particular implementation can be recommended?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Peter Kofler
  • 9,252
  • 8
  • 51
  • 79
  • 5
    Some university courses use gforth (http://www.complang.tuwien.ac.at/forth/gforth/) which is good to start as well. – Peter Kofler Oct 29 '10 at 06:35
  • 2
    The question "*is it practical to learn and use Forth?*" has sadly been deleted. If the OP or someone with 10k reputation (required to view deleted posts) can access this post and cache/save it somewhere, that would be great - it sounds like it would have been an interesting question (although I acknowledge its offtopicness/unsuitability for SO). – i336_ Jan 28 '16 at 02:33
  • @Peter Koffer Why don't you provide an answer, if you answer the question. That is not what comment is for. – Albert van der Horst Nov 02 '20 at 13:23
  • 1
    The deletion of the question is wrong. It is perfectly sensible to select an implementation that is favourable to first steps in Forth. That is arguable and not opinion based. Is a moderator gaining points for deleting a question? – Albert van der Horst Nov 28 '21 at 09:47

9 Answers9

15

Win32Forth is really fantastic, as mentioned above. It has a nice integrated development environment and is a pretty modern implementation that seems to match up very well with the standards as well as including some more experimental but widely-accepted features.

I use Gforth, but I also use Vim to edit source files. :) Gforth is good and "classic" as far as the features it supports. It gives you a very "old school" Forth experience without being overly quirky to use. (Some free Forths do odd things with their command lines and such - I use Brodie's "Starting Forth" as the model of how a Forth interpreter should behave.)

I looked at SwiftForth, which is a very nice "high tech" Forth system that goes well beyond what the classic Forths offer in terms of language features and really brings Forth into the modern programming world. If you want to actually do Forth programs professionally, SwiftForth looks like it can handle just about anything you want to do with it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hdan
  • 311
  • 2
  • 3
  • Yes, propably the best to start. The (kind of) IDE has syntax coloring and WinForth ran almost all of my code developed with gforth (in some course). The help and word index are a bit raw, but helpfull nevertheless. – Peter Kofler Oct 29 '10 at 06:34
9

Some time ago I evaluated 4tH, an implementation of Forth. I think it meets all of your requirements. For instance the compiler is only 61 KB. There is also full support for floating point numbers, important if you want to try to use it for technical/scientific purposes.

4tH runs on most operating systems, including MS-DOS, MS-Windows (both 16 bit and 32 bit), Linux, Coherent, AIX, SunOS, BOS, BSD, Mac OS X, BeOS, RISC OS, etc. Download (Windows installer, 1.5 MB, includes the manual). Manual (PDF, 1.1 MB).

There is an active community centered around the Google Group 4tH-compiler. For instance today I received two messages.

Please note that in 4tH you can't define your own defining words (words executing at compile time). This is not a serious limitation, unless you want to cover advanced Forth features.


To get you started (as this is not very clear from the manual or the interactive compile), after installation copy the compiler, 4th.exe, to an empty folder, make two files in this directory, HelloWorld.bat and HelloWorld.4th, and run HelloWorld.bat:

HelloWorld.bat:

    4th.exe cx HelloWorld.4th
    pause

HelloWorld.4th:

   : hello ." Hello from XYZ!" cr cr ;
   hello
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • I had a look. 4th definitely sounds good. I will give it a try. – Peter Kofler Mar 21 '10 at 09:47
  • I tried it. Although it seems to be ANS compliant, I could not get it run as easily as WinForth or gforth. The documentation is not clear if it's a real Forth or just something quite similar to Forth developed out of a postfix calculator. – Peter Kofler Oct 29 '10 at 06:32
3

SwiftForth. It isn't self-consciously small and compact; it just happens to be. It's easy to use (LOCATE WH EDIT , a nicer than usual WORDS), comes with two books, and has an excellent mailing list with over a decade of archives. The evaluation version won't let you compile turnkey apps or DLLs; it still provides an excellent console for a student, and can support scripts in the usual ways. Quick Windows examples:

: sleep-monitor ( -- )
  HWND_BROADCAST WM_SYSCOMMAND SC_MONITORPOWER 2 SendMessage drop ;


library dnsapi.dll
( ... DLL imports, constants ... )
variable results
: DnsQuery ( z -- res )
  DNS_TYPE_A 0 NULL results NULL DnsQuery_UTF8 ;

: resolves? ( z -- f )
  DnsQuery if false exit then
  results @ DnsRecordListFree true ;


\ an example use of the dialog compiler
\ this compiled DSL is an example of something that 4th
\ precludes with its "not ... serious limitation"
DIALOG (HELLO-ABOUT)
[MODELESS " About Hello" 10 10 120 70
   (FONT 8, MS Sans Serif) ]
\  [class           text                        id   x   y   sx xy ]

   [CTEXT           " HELLO"                    -1  10  10  100 10 ]
   [CTEXT           " (C) 1997 Forth, Inc."     -1  10  25  100 10 ]
   [CTEXT           " http://www.forth.com"     -1  10  35  100 10 ]
   [DEFPUSHBUTTON   " OK"                     IDOK  35  50   50 14 ]
END-DIALOG
ayrnieu
  • 1,839
  • 14
  • 15
  • 1
    That pretty clearly is NOT a screen-based FORTH, and I saw too much stream-of-consciousness run-on code in D85, which was also not screen-based. – John R. Strohm Feb 04 '14 at 13:05
3

Download Gforth for PC and Android.

Tinker with it using it as a calculator, solving simple problems, Fibonacci, solving the quadratic a b c, etc.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
skvery
  • 336
  • 2
  • 16
3

I realise they might not meet all your requirements but the following Forth-like languages might also interest you from a learning perspective.

Additionally, I have found the Re-Factor blog to be a good introduction to Factor.

Martin Smith
  • 213
  • 3
  • 10
2

I recommend ciforth, as you're a Windows user the version built for Windows is known as wina: an MS-WIndows NAtive Forth.

ciforth is a small system written in NASM assembler, and comes with a similar interface for a wide variety of systems. It's small, fast, classic (blocks ftw), easy to use as it's old school, comes with a ton of documentation and a wordlist that isn't overwhelming like Gforth's (the wordlist for Lina is here, the only difference between lina and wina are in words that access the underlying OS: linux/MS-Windows).

Gforth has a lot of bloated definitions and some of Starting Forth won't work in it, for example.

The only thing the official release of ciforth lacks is a floating point stack, but Forth can deal with fixed point incredibly well (if one reads Starting Forth, one learns about how to use it). wina versions can call dll functions just fine, in 32 and 64 bit, but can also make turnkey applications that call dll functions. Beta releases have floating point as a loadable extension.

dch
  • 213
  • 1
  • 5
  • 1
    [Being the author] I lost a year of development time adopting to Debian rules. In the end lina was not accepted anyway. Otherwise the floating point would be in the official version now. (It is present in the beta version and has had some considerable burn in time now.) – Albert van der Horst Nov 02 '20 at 13:18
2

If you can find a copy of FORTH Inc's old polyFORTH, and an old x86 that can run it, this is the language used in Leo Brodie's original "Starting FORTH". It is a clean and very robust FORTH.

John R. Strohm
  • 7,547
  • 2
  • 28
  • 33
  • 1
    And instead of an old x86 you could use [DOSBox x86 emulator](http://www.dosbox.com/download.php?main=1) that runs on most modern Windows machines -- I've used it successfully thruogh to WinXP and Win7. – Assad Ebrahim Feb 04 '14 at 10:32
1

Win32Forth worked well for me.

Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
0

durexForth is an ANS compliant C64 Forth and very small.

agc
  • 7,973
  • 2
  • 29
  • 50
Polluks
  • 525
  • 2
  • 8
  • 19