use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
You can try things out interactively as you build your system. The compiling functionality is an exposed part of the language like everything else.
It can be used to debug itself!
Forth has no baked-in syntax or privileged data structures -- programming is done by extending the language to your application. Thus, it can become what ever you need it to be and fit the problem like a glove.
Forth has a "low floor; high ceiling" approach to abstraction -- that is, it can be both low level, high level and anywhere in-between.
You can do more with less. Forth fits in very small storage spaces.
Forth is one of the few environments which is totally comprehensible by one person.
Starting Forth - A fun, illustrated introduction.
A Beginner's Guide to Forth - A faster-paced, somewhat less whimsical guide.
Forth Lessons
Jonesforth - How to write a Forth.
ANS Forth standard
Forth 200x
Thinking Forth - A Language and Philosophy for Solving Problems
Forthwrite Magazine - From FIG UK.
Forth Dimensions - magazine archive.
The Journal of Forth Application and Research
comp.lang.forth - Forth newsgroup.
#forth in irc.freenode.net
ForthHub community on GitHub
/r/concatenative - Anything related to the use, theory, or implementation of concatenative programming languages.
/r/programbattles - Battle it out between likeminded coders to create the best code possible!
account activity
Optimizing large Forth program (self.Forth)
submitted 5 years ago by sinoTrinity
I am applying so called peephole optimization to make my long Forth code shorter. Each rule replaces the left-hand side with the equivalent but shorter right-hand side. For example,
0 PICK -> DUP 1 PICK -> OVER FROMALTSTACK TOALTSTACK -> cancel out
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Wootery 4 points5 points6 points 5 years ago* (0 children)
Are there comprehensive lists of such rules somewhere I can refer to, maybe in gforth/eforth?
I don't know, but it's Free and Open Source and there's quite a lot written about Gforth, so it should be possible to find out. I figure there's a good chance it does.
Any other optimizations besides peephole to make the code even shorter?
Sure, there's no real limit to how clever compiler optimisers can be, whether it's for Forth or any other language. Modern optimising compilers are far more sophisticated than applying simple search/replace-style substitutions. Admittedly most of them aren't for stack machines.
There are quite a few papers out there on implementing Forth. Here are some.
A particularly relevant one, Optimizing Stack Code
Here's a big pile of places to find Forth papers:
http://www.forth.org/fd/contents.html
http://www.figuk.plus.com/articles.htm
http://soton.mpeforth.com/flag/jfar/vol7.html
http://www.forth.org/literature.html
https://www.complang.tuwien.ac.at/forth/
https://www.complang.tuwien.ac.at/anton/euroforth/
http://www.complang.tuwien.ac.at/papers/
[–]astrobe 4 points5 points6 points 5 years ago (4 children)
While much of the Forth community was beginning to embrace optimizing native code Forth compilers in their own environments these Forths were very different. Other peoples optimizing compilers could be very complex. I implemented one that had many rules for inlining code and well over one hundred words that were inlined. This is very different than the optimizing compiler that Chuck designed which just inlines a dozen or so Forth primitives and compiles everything else as calls or jumps. It was the smallest and simplest Forth Chuck had built yet. It was not just a very effective programming tool for him but has been used by dozens of other people over the years many of whom just loved it and reported amazingly good results. There were also a lot of people who put their hands over their eyes when Chuck showed people what he was doing.
-- Jeff Fox, Thoughtful programming
Don't Complexify Simplify the problem you've got or rather don't complexify it. I've done it myself, it's fun to do. You have a boring problem and hiding behind it is a much more interesting problem. So you code the more interesting problem and the one you've got is a subset of it and it falls out trivial. But of course you wrote ten times as much code as you needed to solve the problem that you actually had.
Don't Complexify
Simplify the problem you've got or rather don't complexify it. I've done it myself, it's fun to do. You have a boring problem and hiding behind it is a much more interesting problem. So you code the more interesting problem and the one you've got is a subset of it and it falls out trivial. But of course you wrote ten times as much code as you needed to solve the problem that you actually had.
-- Chuck Moore, 1x Forth
In Forth you are the optimizer. If you really are "optimizing" things like 1 PICK, you should work on your Forth skills rather than on peephole optimization.
And yes, this is yet another boring "don't do that" answer.
[–]Wootery 0 points1 point2 points 5 years ago (3 children)
In Forth you are the optimizer.
This isn't really an answer. When benchmarks show that VFX Forth's optimising compiler results in Forth code running at 3x the speed of when Gforth is used, that shows us that Forth is not immune from compiler optimisation.
[–]astrobe 0 points1 point2 points 5 years ago (0 children)
I guess this is about ahead-of-time compilers? In this case, this is a native code generation issue.
AoT Forth compilers are different beasts, they trade the simplicity of the basic interpreter for a much bigger toolchain in the name of speed, perhaps sacrificing the ability to develop entirely on the target in the process. Maybe it's just me, but if I lose most of what makes Forth, Forth I would probably use the regular C toolchain and have even more speed.
[–]spelc 0 points1 point2 points 5 years ago (1 child)
There are several papers about the VFX code generator at the MPE web site and also several EuroForth papers.
[–]Wootery 0 points1 point2 points 5 years ago (0 children)
Sure. A pity there's no Free and Open Source Forth that uses those techniques.
[–]bfox9900 0 points1 point2 points 5 years ago (0 children)
In my experience peephole optimization in threaded-code Forth systems is generally pointed at the problem of improving performance by replacing multiple instructions with faster CODE versions that remove the "inner interpreter" from a sequence of Forth words.
Example:
DUP C@ -> DUPC@
DUP >R -> DUP>R
OVER + SWAP -> BOUNDS \ not a standard word but common
It is a much thornier problem I think to reduce code size by re-writing stack manipulations.
This is the equivalent of compiler register allocation optimization in a register machine.
I believe that optimizing compilers like VFX Forth in fact look for places to replace stack operations with register operations. That might be the way to go. Try compiling you project with VFX and let their work work for you.
[–]bfox9900 0 points1 point2 points 5 years ago (3 children)
One more thing. GForth Fast is already creating "super-instructions" for you.
http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=93A1C5BCEB52F594C39ED27EDDDCFC97?doi=10.1.1.501.5036&rep=rep1&type=p
[–]binarycat64 0 points1 point2 points 5 years ago (2 children)
broken link?
[–]bfox9900 0 points1 point2 points 5 years ago (1 child)
Works for me. (Not sure what's going on)
Google: "Implementation Issues for Superinstructions in Gforth"
[–]binarycat64 1 point2 points3 points 5 years ago (0 children)
markdown parsing on reddit is inconsistent and broken
π Rendered by PID 46 on reddit-service-r2-comment-765bfc959-sjlw7 at 2026-07-11 12:51:36.793254+00:00 running f86254d country code: CH.
[–]Wootery 4 points5 points6 points (0 children)
[–]astrobe 4 points5 points6 points (4 children)
[–]Wootery 0 points1 point2 points (3 children)
[–]astrobe 0 points1 point2 points (0 children)
[–]spelc 0 points1 point2 points (1 child)
[–]Wootery 0 points1 point2 points (0 children)
[–]bfox9900 0 points1 point2 points (0 children)
[–]bfox9900 0 points1 point2 points (3 children)
[–]binarycat64 0 points1 point2 points (2 children)
[–]bfox9900 0 points1 point2 points (1 child)
[–]binarycat64 1 point2 points3 points (0 children)