Forth Reusability

Forth has a very different unit of reuse than most other languages: source code.

While it is true that Perl, Smalltalk or Lisp also rely on source code sharing as the exclusive means of reuse, most MainStreamLanguages? such as C, C++, Java, Fortran or even less successful ones such as Pascal, ADA, Oberon or Modula2 offer binary code reuse right out of the box, on a given platform.

Reuse, in Forth, should not so much be construed as a means of spreading knowledge across different projects as much as the means by which an individual project is put together.

Effective Forth reuse is done by factoring, where elegant and efficient reuse of your own low level building blocks can be attained at higher levels.

Moreover, effective factoring results in the re-use of entire vocabularies of words (loosely analogous to what other languages would call a 'library'). Since Forth source is substantially easier to transfer than binary object code, there is actually astonishingly little need for this thing called 'libraries.' Pre-load the relevant code sequences, and henceforth, all other loaded applications are free to use them. The end result is the same - code re-use.


One of the things that makes programming "in the large" possible is having types. Forth not only eschews higher-order types, it won't even deign to support any primitive types. Floating point in AnsForth has truly alien syntax, forcing many forth implementations to outright rebel against it. But mostly, when I do something like WASHER TIME-LEFT, I don't want the result being fed into SET-TEMP. Time, temperature, different incompatible types. Granted, C is no help either, nor is C++ with its inability to subclass "primitive" types, but Forth won't even give me so much as a peep in passing any int for any string value. Anyone who hates C pointers cannot help but curl their lip at the "everything can be a pointer" treatment of Forth.

Yes, it's possible to modify the Forth compiler to support type annotations. To my knowledge, no one does so, or in typical fashion, locks it up in a proprietary commercial compiler (the outright venom expressed by many forthers against free solutions strikes me as one of the worse SocialProblemsOfForth?)

Hmm... not much here about reusability. Move to ForthFlames, maybe?

Aside from that, Forthers I've met go way beyond liking free solutions to making their own entire homebrew systems. A lot of that is possible due to code sharing in the community. And for typing, google around for StrongForth (which is free). Regular Forth doesn't claim to have any more typing than AssemblyLanguage (since it's a macro assembler for a virtual stack machine).

I did google for strongForth, and its page has been gone for over a year, the download is missing even from the wayback machine and I've found no mirrors. I retract my claims about free forth solutions though, as it's not true of the current generation of forthers.

I found a copy of strongForth at http://home.vr-web.de/stephan.becher/forth/.

A more robust embodiment of DynamicTyping in Forth can be found in FactorLanguage.


ForthLanguage, ForthIsDead, ForthPessimism, ForthReadability, ForthPortability, ForthReusabilityFlames, ReinventingTheWheel


EditText of this page (last edited July 13, 2006) or FindPage with title or text search