3 ms·
> Can you elaborate on what is special about Forth? Not the OP here, but I'll give it a partial shot. The power of Forth comes from its extremely simple syntax
by tom_mellior 10y ago
> Can you elaborate on what is special about Forth?
Not the OP here, but I'll give it a partial shot. The power of Forth comes from its extremely simple syntax and the ways you can extend it. A Forth program is just a sequence of "words", which are any sequences of non-whitespace characters separated by whitespace. Users can define new words. These can be "parsing words" which can consume the input that follows them in arbitrary ways.
So, for example, given appropriate definitions, this is a valid Forth program:
ax bx mov \ mov ebx,eax
3 # ax mov \ mov eax,3
(this is taken directly from GForth's inline assembly docs: https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/386-Assembler.html#g_t386-Assembler https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/386... ; the \ introduces a comment to the end of the line and shows the assembly code as it would be written in a traditional assembler)
Or, given appropriate definitions, this is a valid Forth program:
select * from customers
You see where this is going: Programmers have a lot of possibilities to extend the language or implement embedded DSLs (which is pretty much the same thing in Forth). A popular demo of this power are things along the line of http://c2.com/cgi/wiki?ForthObjects http://c2.com/cgi/wiki?ForthObjects, where an object system for Forth (which is not object oriented at all) is implemented in 20 lines of code.
All that said, it's ugly and complex and I always find it difficult to figure out what's going on with all the strangely named concepts and compile-time effects and run-time effects of everything. But still. Interesting stuff.
- bogomipz 10y agoThank you, I certainly see the power in that. Thanks for the time to answer.