ForthHub/discussion

Use cases asking for forth

Opened this issue · 7 comments

Hi there,

maybe it's a dumb question. Maybe a nice starter. But I kinda feel limited of using forth mostly in the context of writing a forth system from scratch or the obvious "embedded system" usage of it.

Most stuff besides either forth systems itself or embedded systems are not obvious to me.
Yes you can write everything theoretically in forth but what use cases are from the structure of the
language and it's syntactical or environmental features one step away?

Using prolog to code an Expert System is not far reached. Using lisp for the same or for a use case which asks for the abstraction and list processing is also one step away.
Using C for embedded programming or writing a unix program is also one step away.

I leave that here maybe you can add some more worked out ideas :-)

Return-oriented programming is an attack based on piecing together a Forth-like programming language out of small segments of already existing "innocent" code that ends in RET

https://en.wikipedia.org/wiki/Return-oriented_programming
http://esolangs.org/wiki/Return-oriented_programming

Embedded scripting language.

Examples:

I'm currently writing a crude emulator for the 65816 (the big sibling of
the famous 6502) in Gforth (https://github.com/scotws/crude65816). I chose
Forth because I need the practice (as the code shows, cough) and there will
be a SBC based on the 65816 at some time in the future that will in fact
run Forth itself. Also, I wanted to make the code base very small so the
emulator itself has a chance of running on the 65816, just because that
sounds like a fun idea.

Y, Scot

On Sat, Oct 31, 2015 at 12:16 PM, Lars Brinkhoff notifications@github.com
wrote:

Embedded scripting language. E.g. Ficl and Open Firmware.


Reply to this email directly or view it on GitHub
#14 (comment).

Scot W. Stevenson - scot.stevenson@gmail.com
Twitter: @scotstevenson - GitHub: https://github.com/scotws
Blog USA Erklärt: http://usaerklaert.wordpress.com
Blog BYO 8-Bit SBC: http://uebersquirrel.blogspot.de/

Forth has only one syntax element, which is white space. This means that the keywords like if, until, ... are not special like in most other languages but can be modified for your purpose. C cannot be extended to be C++, the compiler needs to be modified. As Forth is essentially an interactive compiler, you can modify Forth to have classes in as few as 15 lines (mini-oof)

So Forth enables you heavy syntax adoption to your use case (see also literate programming). You do not parse a config file in Forth, instead you might create a new wordset, implement the configuration file syntax and just include the file. Klaus Schleisiek parses VHDL directly with GForth to automatically extract some features.

For me the highly adaptive syntax is the main selling point for Forth. The fact that the system fits into a the few k of a micro controller is fortunate, but as embedded system memory only gets bigger we cannot argue the size forever ;)

@GeraldWodni writing parsers in forth is more like of a more hidden craft than something really obvious.
I tried a couple of times to bend the syntax so that I could get some basic parsing.
But it's not pretty and I would say that Chuck wouldn't be "proud" about how that code tends to
look like.

Maybe I'm wrong, but that is how I see it and I'm not new to the language.

There are some hint's there :

http://colorforth.com/POL.htm

2015-10-31 21:01 GMT+01:00 Josef P. Bernhart notifications@github.com:

@GeraldWodni https://github.com/GeraldWodni writing parsers in forth is
more like of a more hidden craft than something really obvious.
I tried a couple of times to bend the syntax so that I could get some
basic parsing.
But it's not pretty and I would say that Chuck wouldn't be "proud" about
how that code tends to
look like.

Maybe I'm wrong, but that is how I see it and I'm not new to the language.


Reply to this email directly or view it on GitHub
#14 (comment).

Mat2 commented

@Phantasus: Compared to writing a parser, it is appropriate however dependent of the syntax and semantic to be implement maybe more ornate or obfuscating to proceed so. Usually, my experience is that extending the Forth system is at least an effort efficient alternative to writing a complex parser. I know two nice examples of this approach. One is a Basic compiler and the other one a XML parser. The latter one combine a simple filter for converting XML files into an easier representable notation and back with a word set for the tags.