'''Forth''' is both a [programming language] and programming environment based on stacks and their manipulation. It uses postfix notation (aka. [RPN%|%Reverse Polish Notation]), best-known from its use in HP calculators, and [http://en.wikipedia.org/wiki/PostScript%|%PostScript]. The following example shows a basic mathematical calculation to demonstrate the postfix notation: ======none 1 2 + 3 * 4 / ( comments start with open paren and extend to close paren) ====== Compare to Tcl (infix style) ====== expr {(1+2)*3)/4} ;# comments ====== or, if [Math Operators as Commands%|%math operation commands] are imported (prefix style): ====== / [* [+ 1 2] 3] 4 ====== ** See Also ** [A different FORTH] ,by [JBR]: [Trying FORTH in Tcl] ,by [jcw]: [RPN in Tcl] ,by [RS]: [RPN again] ,by [RS]: [HP Calculator Simulations]: [GPS RPN] ,by [GPS]: [HolonTForth] ,by [wej]: [TclForth] ,by [wej]: [https://code.google.com/p/toka/%|%toka]: a concatenative programming language related to Forth ** Quotes ** "Forth seems to have too little syntax to be manageable": - [KBK] ,[Tcl Chatroom] ,2013-12-26 ** Documentation ** [http://c2.com/cgi/wiki?ThinkingForthTips%|%Thinking Forth Tips]: ** Reading ** [http://www.techworld.com.au/article/250530/a-z_programming_languages_forth/%|%The A-Z of Programming Languages: Forth] ,Naomi Hamilton ,Computerworld ,2008-06-27: [http://developers.slashdot.org/story/01/09/11/139249/chuck-moore-holds-forth%|%Chuck Moore Holds Forth] ,slashdot ,2001-09-14: [http://equi4.com/moam/doomed.html%|%Why compilers are doomed] ,[jcw] ,November 2000: ** Description ** Forth consists of words (commands) that exchange parameters on a stack. This simple concept implies [postfix notation], and [RPN] in mathematical expressions. [Chuck Moore] created FORTH in 1970. An interesting article about FORTH ,[http://www.colorforth.com/byte.htm%|%Threads of a FORTH Tapestry], appeared in the August 1980 issue of ''Byte'' magazine. Related to this is [1% the code], a shocking paper by Chuck Moore. Often over the years, FORTH and Tcl have been compared because of the mindset in both to write lots of procs/words to do one's work. There are quite some characteristics that are shared between the two languages: * reflection * interactivity * extensibility * typeless (Forth) http://c2.com/cgi/wiki?TypelessVsDynamic%|%versus%|% dynamically typed (Tcl) * ... ** Tutorials ** [http://www.ece.cmu.edu/~koopman/forth/hopl.html%|%A Brief Introduction to Forth], by Philip J. Koopman Jr. ,1993: [http://www.xs4all.nl/~thebeez/ForthPrimer/Forth_primer.html%|%And so Forth] ,J.L. Bezemer ,2001-04-25: a primer [http://web.archive.org/web/20041031091827/http://www.geocities.com/SiliconValley/Bay/2334/4thtutor.htm%|%Learn 4tH th easy way]: [http://home.iae.nl/users/mhx/sf.html%|%Starting Forth] ,Leo Brodie, 1981: An introduction to Forth. [http://thinking-forth.sourceforge.net/%|%Thinking Forth] ,Leo Brodie, 1984: Thinking Forth captures the philosophy of the language to show users how to write more readable, better maintainable applications. ** Resources ** The [http://www.forth.org/%|%Forth Interest Group] (FIG): The Forth Interest Group (FIG) was a world-wide, non-profit organization for education in and the promotion of the Forth computer language. Forth [http://en.wikipedia.org/wiki/Forth_%28programming_language%29%|%Wikipedia article]: The [http://thebeez.home.xs4all.nl/4tH/%|%4tH] compiler: See also the [https://web.archive.org/web/20021001022931/http://www.xs4all.nl/~thebeez/4tH/foldtree.html%|%historical site] [http://www.forthos.org/%|%ForthOS]: a complete, standalone operating system for the PC (x86) [http://pygmy.utoh.org/riscy/%|%Riscy Pygness]: Pygmy Forth for the ARM Leo Brodie's "Starting Forth" as a [starkit] for [Microsoft Windows]/[Linux]/[Solaris] can be found here [http://www.equi4.com/pub/sk/brodie_sf.kit], based on the web version of the book at [http://home.iae.nl/users/mhx/sf.html]. ([AMG]: Or see [http://www.forth.com/starting-forth/] for another version of the same book.) [AK]: This [starkit] seems to need a package 'scripdoc', which is not in the [starkit]. [LV]: That package was a part of the original [tclkit]s. It still is in my [tclkit] of [tcl] 8.4.9 for sparc solaris. Perhaps it isn't in the tclkit lite? ---- Several Forths have bound to [Tk] for their [GUI] toolkit needs. V6 [http://www.amresearch.com/v6/] is a commercial Forth based on Gforth available for [Linux]es (and *[BSD]? and [MacOS X]?). ---- [Zarutian] 2006-09-24: Does an Tcl interpreter in Forth exists? [Zarutian] 2006-09-27: Or do I have to write one? [wdb] Please yes! [Zarutian] 2007-06-20: Hmm... that would require Forth words for: * string manipulation (slicing and splicing) * string comparison and something more probably. [tb] 2007-07-17: @wdb, Do you think of a string stack? How much of a FORTH system would be appropriate for emulation? A true 2stack machine with a "Dictionary space", an "Inner interpreter", an "Outer interpreter", compilers and defining words, complete with its own command loop? -- [wdb] Not a string stack, but some creations with ''''. All strings shall be unique, identified by their memory address, and be immutable. Depending on operations, values internally implemented with multi-pointer (one for string-processing, one for list-processing, one for float-processing), where not-used or outdated pointers are reset to null. -- I'm just dreaming of a '''very''' high-performant Tcl ... [wdb]: I'm working on a string object in [gforth] where uniqueness of char sequences ist granted. Instead of garbage collect, memory recycling triggered automatically on forgetting. Built as "black box" where you can use a few words provided to handle the data without knowledge about internals. Should be a solid base for a Tcl interpreter. If anybody is interested, I'm happy to hand it out. [escargo]: It might be interesting to have a [http://en.wikipedia.org/wiki/PostScript%|%PostScript] system instead. PostScript is both a stack-based VM and has strings and dictionaries. [LEG] 2007-09-19: just implemented [f4t]. Why would you want to do string processing on stacks in Tcl? Why would you want to implement just another graphics language in Tcl. Both things are handled fine in Tcl/Tk. IMO Forth in Tcl should enhance, complement Tcl in an area where Tcl needs it or where Forth functionality is nice to have. [wej] 2008-04-29: If you want to write Tcl programs in Forth: [HolonTForth] compiles Forth to Tcl source files and uses Tcl as the Forth machine. ---- [ZB] 2008-07-06: Every description of Forth focuses on using stack, RPN and so on - but I'm interested in such trivial things, like f.e.: is it possible to write Forth-programs with nice user interface (at least curses-based, if not Tk/GTK-like GUIs)? Any examples? Is event-based programming possible using Forth? A google-search for "event-based programming in forth" revealed nothing. [tb] 2008-07-07 - Yes, it should be possible by creating an event stack, holding addresses of handlers (as a first approach), but you'd have to program and enter your own event loop, because a classical FORTH inpterpreters loop only recognizes ONE input stream, which must be ASCII characters. [escargo] 2008-07-07: One of the original FORTH systems was a time-share system that supported 30 users on a 32K 16-bit word Honeywell H316 system. Every user got an input buffer and a private dictionary. A context switch between users required changing the value of 3 pointers (if I remember correctly). So if FORTH could do that, then using FORTH to create an event loop with "do one event" would seem to be possible. [ZB]: I was digging for more information meanwhile, and I've found, that Forth is something like "OS and set of tools for creation of one's own language" rather - and not "just another programming language". Looks very interesting. One can f.e. implement interrupts handlers. [tb]: Yes, this is called metaprogramming and in this aspect of creating your own problem-related language, FORTH is quite similar to Tcl. Instead of namespaces you have "vocabluaries" and instead of procedures you have "words". But, with the lack of a seamless integrated widget kit, like Tk in Tcl/Tk, FORTH will always only be a better assembler, heading for device drivers, document processors (Postscript) or other non-interactive tasks. PS: I remember a nice implementation of FORTH, running on Atari-ST under GEM. It managed windows, menus and events and fitted nicely into the Ataris OS. It was called "Volksforth" and followed the Forth'83 path. Perhaps that'd be a starting point for some X-Forth or WIN-Forth? [ZB]: Although I've found meanwhile something called "TkForth" (seems to be discontinued), but it can be seen as kind of exercise rather, because Forth isn't any "TCL-replacement" (neither competitor); it's quite different tool. Although most probably one could build, using Forth, ones own "Tk" from the ground up - there is a question: "do I need to?". It seems to me - from that few docs I've read until now - that proper (target) use of Forth is "standalone" rather than on top of any OS. We're losing some (or even many) of its advantages otherwise. Someone described Forth as "Lego among the programming languages" (as TCL is among the scriptic ones). [tb] They seem to have found a way to call routines from the Tk library. Then it creates some defining words (compilers) for widget creation. So they compile widgets as words into the dictionary space. A very FORTHish approach. :) Running FORTH in standalone mode isn't really a prefered way, but leads to a small footprint ready to be burnt to EPROM. Most modern FORTHs like GForth, BigForth et.al. use the underlying OS for screen output and disk access. They can be extended to call foreign library functions including those from the Tk library as shown with TkForth. <> Language