Live data from Hacker News

Forth: The Hacker’s Language

hackaday.com

61–70 of 111 posts

Re: Forth: The Hacker’s Language

#61
post #44

One of the most complex games Starflight of the 80th's is written in Forth. I had a lot of fun decompiling it. https://github.com/s-macke/starflight-reverse It turns out to be very portable because the assembler code is only about 1000-2000 lines. The rest is implemented in Forth itself. They use indirect threading to produce very dense code. They kept even most of the debugging symbols inside the code and kept the f…

At one point 10ish years ago the starflight source code was posted online by one of the authors, but it went back down pretty quickly. Someone might have a copy though. A few of the files are on archive.org, but not the main body.

http://web.archive.org/web/20030214111810/http://www.sonic.n...

Re: Forth: The Hacker’s Language

#62
post #26

I'm a embedded software dev and write code all day in C. Sure enough forth comes up in conversations once in a while as does other ideas like Python, JS, Lua etc.. Of all the alternatives to C, Forth is the only one which groks hardware. This is particularly important for embedded development. Any realistic alternative to C must understand interrupts, memory mapped registers etc.. Forth is the only one in which this…

> Forth is the only one in which this is possible. Every other example I've seen always uses C for "low-level" access or a libraries. If you need to do that, then you won't win over embedded devs like me. Not really. https://www.mikroe.com/mikrobasic/ https://www.mikroe.com/mikropascal/ http://www.astrobe.com/default.htm http://www.adacore.com/gnatpro/embedded http://www.ptc.com/developer-tools/apexada http://www.ghs…

Some years ago when Java was relatively new, I had come across this company Esmertec, which was making Java toolchains for embedded devices. Site seems to be still there, not sure about the company:

www.esmertec.com

Re: Forth: The Hacker’s Language

#63
post #26

I'm a embedded software dev and write code all day in C. Sure enough forth comes up in conversations once in a while as does other ideas like Python, JS, Lua etc.. Of all the alternatives to C, Forth is the only one which groks hardware. This is particularly important for embedded development. Any realistic alternative to C must understand interrupts, memory mapped registers etc.. Forth is the only one in which this…

> Forth is the only one in which this is possible. Every other example I've seen always uses C for "low-level" access or a libraries. If you need to do that, then you won't win over embedded devs like me. Not really. https://www.mikroe.com/mikrobasic/ https://www.mikroe.com/mikropascal/ http://www.astrobe.com/default.htm http://www.adacore.com/gnatpro/embedded http://www.ptc.com/developer-tools/apexada http://www.ghs…

You are right. I completely forgot about ADA and representative clauses. I remember reading that representative clauses mapping to register fields. And to be fair, basic and pascal also can be used for bare metal stuff.

Re: Forth: The Hacker’s Language

#64

I'm a embedded software dev and write code all day in C. Sure enough forth comes up in conversations once in a while as does other ideas like Python, JS, Lua etc.. Of all the alternatives to C, Forth is the only one which groks hardware. This is particularly important for embedded development. Any realistic alternative to C must understand interrupts, memory mapped registers etc.. Forth is the only one in which this…

I wrote a proprietary app in Lisp (using Clozure Common Lisp) for Windows. In the licensing code, I needed to get the list of network adapters and also the volume ID of the installation drive. It was easy to call the Win32 functions directly. Note that enumerating the adapters requires walking linked list of C structures returned by the GetAdaptersInfo function (to which you have to specify an allocated memory buffer where that list will be stored.) I did that all in Lisp; not a line of C.

Re: Forth: The Hacker’s Language

#65
post #26

Earlier quoted context omitted.

> Forth is the only one in which this is possible. Every other example I've seen always uses C for "low-level" access or a libraries. If you need to do that, then you won't win over embedded devs like me. Not really. https://www.mikroe.com/mikrobasic/ https://www.mikroe.com/mikropascal/ http://www.astrobe.com/default.htm http://www.adacore.com/gnatpro/embedded http://www.ptc.com/developer-tools/apexada http://www.ghs…

You are right. I completely forgot about ADA and representative clauses. I remember reading that representative clauses mapping to register fields. And to be fair, basic and pascal also can be used for bare metal stuff.

Ada isn't a dynamic language, so it doesn't really apply here; you don't get to use it in the ways like Forth; like having a boot ROM with an Ada REPL (laugh).

Of course there are other systems programming "monolithic executable" programming languages that allow straightforward access to memory mapped hardware registers.

Re: Forth: The Hacker’s Language

#66
post #61
post #44

One of the most complex games Starflight of the 80th's is written in Forth. I had a lot of fun decompiling it. https://github.com/s-macke/starflight-reverse It turns out to be very portable because the assembler code is only about 1000-2000 lines. The rest is implemented in Forth itself. They use indirect threading to produce very dense code. They kept even most of the debugging symbols inside the code and kept the f…

At one point 10ish years ago the starflight source code was posted online by one of the authors, but it went back down pretty quickly. Someone might have a copy though. A few of the files are on archive.org, but not the main body. http://web.archive.org/web/20030214111810/http://www.sonic.n...

Thanks for posting the link. I found the archive a few month ago and downloaded the few documents that were left. The table here

https://github.com/s-macke/starflight-reverse/blob/master/sr...

is based on these documents and I filled some gaps of the symbol table. To start the game they used the word "LET-THERE-BE-STARFLIGHT", in the binary you see only part of it: "LET-TH".

I wish this "someone" would provide a full copy of the archive :)

Re: Forth: The Hacker’s Language

#67
Forth is a hacker's language only when we take a narrow definition of "hacker" as someone who cares about making a device field-programmable in the easiest, smallest way that doesn't completely suck, and can somehow get things to work without caring what the code looks like or whether anyone understands it, including the same hacker seventeen months later.

Re: Forth: The Hacker’s Language

#68
Amen.

And it is dead simple to implement. I did it in common lisp 3 years ago for an IRC-bot - a lazy Sunday afternoon and 50 lines of code later I was done.

I would not want to write code in Forth on a regular basis, but reading (and making an effort to really understand it) definitely made me a better programmer.

Re: Forth: The Hacker’s Language

#69
post #4

I came to Forth-like languages via PostScript, which has the advantage of a huge built-in graphics library. It very naturally introduces concepts like higher order operations, code as data and data as code.

Can you reccomend any books on PS?

reference manual: https://www.adobe.com/products/postscript/pdfs/PLRM.pdf

tutorial and cookbook (blue book): https://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF

language program design (green book): https://www-cdf.fnal.gov/offline/PostScript/GREENBK.PDF

Re: Forth: The Hacker’s Language

#70

Earlier quoted context omitted.

You are right. I completely forgot about ADA and representative clauses. I remember reading that representative clauses mapping to register fields. And to be fair, basic and pascal also can be used for bare metal stuff.

Ada isn't a dynamic language, so it doesn't really apply here; you don't get to use it in the ways like Forth; like having a boot ROM with an Ada REPL (laugh). Of course there are other systems programming "monolithic executable" programming languages that allow straightforward access to memory mapped hardware registers.

Static languages can have REPLs.
Post reply on HN