Live data from Hacker News

Forth: The Hacker’s Language

hackaday.com

11–20 of 111 posts

Re: Forth: The Hacker’s Language

#11
post #9

This is a how-to-write-a-FORTH tutorial that I wrote a few years ago. It's particularly nice that you get to see how various control structures are implemented, like IF, CASE and even comments! Part 1: http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth... Part 2: http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth... (github mirror: https://github.com/AlexandreAbreu/jonesforth/blob/master/jon... ht…

This is amazing. Thank you so much for sharing this.

Re: Forth: The Hacker’s Language

#12
post #9

This is a how-to-write-a-FORTH tutorial that I wrote a few years ago. It's particularly nice that you get to see how various control structures are implemented, like IF, CASE and even comments! Part 1: http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth... Part 2: http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth... (github mirror: https://github.com/AlexandreAbreu/jonesforth/blob/master/jon... ht…

Thanks, I've loved that piece for a while. I had written a couple of subroutine-threaded forths before that, but you helped me cross the border into indirect threading.

Re: Forth: The Hacker’s Language

#13
post #10

Earlier quoted context omitted.

The more likely culprit is this: > But Forth is also like a high-wire act; if C gives you enough rope to hang yourself, Forth is a flamethrower crawling with cobras. There is no type checking, no scope, and no separation of data and code. You can do horrible things like redefine 2 as a function that will return seven, and forever after your math won’t work. (But why would you?) You can easily jump off into bad sectio…

> Forth code ends up deeply personal, and specific to the current task. That's the point though. You create a domain specific language using Forth and solve your domain specific problems with it.

It wasn't a critique! I find Forth and concatenative languages in general incredibly fascinating. I'm just pointing out that it comes with a trade-off

Re: Forth: The Hacker’s Language

#14
post #10

Earlier quoted context omitted.

The more likely culprit is this: > But Forth is also like a high-wire act; if C gives you enough rope to hang yourself, Forth is a flamethrower crawling with cobras. There is no type checking, no scope, and no separation of data and code. You can do horrible things like redefine 2 as a function that will return seven, and forever after your math won’t work. (But why would you?) You can easily jump off into bad sectio…

> Forth code ends up deeply personal, and specific to the current task. That's the point though. You create a domain specific language using Forth and solve your domain specific problems with it.

Yes, but create "other programmers don't understand my DSL" problem.

DSLs come at a cost.

Re: Forth: The Hacker’s Language

#15
Forth is really neat. It's a rare langauge that has the same abilities as C to deal with hardware, but is a higher level language than assembly, and isn't C. Most languages in common use today have reached a level of abstraction where direct hardware interaction is either impossible or discouraged.

Also, my time with Lisp has taught me that interactive environments are A Good Thing, and Forth is exceedingly interactive, and has better native introspection than many Lisps (when your guts are strewn across the floor, it's hard to hide them).

But for all that is good about it, Forth does have its problems: depending on how well your problem maps to the stack, Forth can be exceedingly painful.

A discussion of Forth's flaws, of course, would not be complete without a link to Yossi Kreinin's now-famous post on the subject: http://yosefk.com/blog/my-history-with-forth-stack-machines....

Re: Forth: The Hacker’s Language

#16
post #14
post #10

Earlier quoted context omitted.

> Forth code ends up deeply personal, and specific to the current task. That's the point though. You create a domain specific language using Forth and solve your domain specific problems with it.

Yes, but create "other programmers don't understand my DSL" problem. DSLs come at a cost.

...And Forth's DSL's are worse than most, by virtue of having minimal syntax, and being bound by the stack. So it's not just the Lisp problem again: it's actually worse.

Re: Forth: The Hacker’s Language

#17

I quite like Forth. It feels like a blend of lisp and apl. And even ml if you squint a bit at it as an applicative as composition system. People on reddit seems to hint at the fact that Forth people stay under the radar because it allow them to design and solve problems in better ways. I wonder how true it is ..

The more likely culprit is this: > But Forth is also like a high-wire act; if C gives you enough rope to hang yourself, Forth is a flamethrower crawling with cobras. There is no type checking, no scope, and no separation of data and code. You can do horrible things like redefine 2 as a function that will return seven, and forever after your math won’t work. (But why would you?) You can easily jump off into bad sectio…

That sounds about right. I've already linked it, but yosefk's take on the subject (http://yosefk.com/blog/my-history-with-forth-stack-machines....) is worth reading, assuming that you've been living under a rock, and thus haven't already.

Re: Forth: The Hacker’s Language

#18

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…

> Any realistic alternative to C must understand interrupts, memory mapped registers etc.. 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.

Forth is a great little language, and a perfect example of how to to do a surprising amount with very little. For more complicated embedded work, however, I've been deeply impressed with Philipp Oppermann's tutorial on writing a kernel in Rust: http://os.phil-opp.com/ You have to limit yourself to Rust's "core" library (instead of the usual "std"), and you won't have a heap until you write one, but it's surprisingly nice. Well, except for debugging double faults. That's never nice. :-/

Here's my toy PIC 8592 interface in pure Rust: https://github.com/emk/toyos-rs/tree/master/crates/pic8259_s... Be careful, it's a subtle chip and I only deal with the basics.

Re: Forth: The Hacker’s Language

#20
post #18

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…

> Any realistic alternative to C must understand interrupts, memory mapped registers etc.. 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. Forth is a great little language, and a perfect example of how to to do a surprising amount with very little. For more complicated embedded work, however, I've been deeply impressed with Philipp Op…

Yeah, but Rust is much more complex than Forth, and really hates baremetal: you can do baremetal in Rust, but it's idiomatic to minimize contact. That works really well in some cases: OS work, for example.

But if you're working in a raw microconroller, you're going to be touching metal constantly, and you won't want anything you don't use slowing you down.

In short, Rust is great, but it doesn't beat Forth in Forth's biggest problem space: programming embedded systems under exceptionally tight size/speed constraints.

Post reply on HN