Live data from Hacker News

Easy Forth (2015)

skilldrick.github.io

31–40 of 128 posts

Re: Easy Forth (2015)

#31
post #19
post #7

Earlier quoted context omitted.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

As I like to say: "C is a language that solves a million problems. Forth is a million languages that solve almost nothing." :-P I've been reading about Forth for 30-40 years. The dual stack is easy to understand. My problem is that I cannot see how control flow works in Forth, e.g. a simple if-then-else. I think that something as fundamental as an if-then-else should be obvious in a useful language. Heck, it's obviou…

>>Forth is a million languages that solve almost nothing." :-P

That brings us to the question, when it was invented and people did use it. What kind of problems were they solving with it?

Re: Easy Forth (2015)

#32
post #19
post #7

Earlier quoted context omitted.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

As I like to say: "C is a language that solves a million problems. Forth is a million languages that solve almost nothing." :-P I've been reading about Forth for 30-40 years. The dual stack is easy to understand. My problem is that I cannot see how control flow works in Forth, e.g. a simple if-then-else. I think that something as fundamental as an if-then-else should be obvious in a useful language. Heck, it's obviou…

> My problem is that I cannot see how control flow works in Forth, e.g. a simple if-then-else.

Hopefully this is helpful: https://www.forth.com/starting-forth/4-conditional-if-then-s...

Re: Easy Forth (2015)

#33
post #7

This has showed up here a few times before (example): https://news.ycombinator.com/item?id=10634918 I'm always interested in hearing people's reactions to Forth though and every now and then you get a cool new story on these threads, so I'm not complaining.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

Every single coder that uses chaining operators is using concatenative programming concepts. Shell piping is also a form of concatenative programming.

Just because you don't specifically use forth does not mean forth is dead.

Re: Easy Forth (2015)

#34
post #14

Forth is very enjoyable, and it's always exciting to see someone new discovering it, but it has three big problems. The first is a technical problem: the forte of Forth is self-hosted developer tooling in restricted environments: say, under 256KiB of RAM, no SSD, under 1 MIPS, under 10 megabytes of hard disk or maybe just a floppy. In that kind of environment, you can't really afford to duplicate mechanism very much,…

Reading lines from a file and handling the strings in memory is what made me stop using it after a 3rd day of advent of code one year. I simply couldn't find a good solution, without a massive excursion into how to use the pad. Such a supposedly simple thing like reading a complete line from a file, yet it stopped me completely. Of course I could have "cheated" and put the input right into the program, but I wanted t…

You should be able to dive in quickly using the very nice forthkit, which finishes with a working shell / REPL:

https://github.com/tehologist/forthkit

It is an implementation of eforth, a portable forth:

http://www.exemark.com/FORTH/eForthOverviewv5.pdf

Re: Easy Forth (2015)

#35
post #7

This has showed up here a few times before (example): https://news.ycombinator.com/item?id=10634918 I'm always interested in hearing people's reactions to Forth though and every now and then you get a cool new story on these threads, so I'm not complaining.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

I've done:

- Accounting system used for real life taxation in my self-employment: https://gist.github.com/lf94/fcdf41776e14fcc289bac652ea8cb4f...

- Software shader rasterizer for image generation: https://gist.github.com/lf94/f74c927e59b4010d9de001fa2ba8791...

- PS4 controller macro system via an RP2040 & ZeptoForth: https://youtu.be/exayMSQfyqk, https://gist.github.com/lf94/2d64917728594516dee6caf7667d2e4...

- Iambic paddle tap interpreter for morse code practice (once again running RP2040 & ZeptoForth): https://gist.github.com/lf94/95516fa39c3339b685e0fde10f17c97...

- Fixed-point number library to run computations on pretty much any CPU in existence: https://gist.github.com/lf94/ca622ebac14d48915ea976f665f832c...

- 1-bit music synthesis experiments to learn how to make music with a beeper (useful in products, such as Tile): https://www.youtube.com/watch?v=IjTihhFG03o, https://www.youtube.com/watch?v=_6f8PURcPEE

And that's all in my rare spare time.

Forth really shines in microcontroller or esoteric computation machines, but further more, people don't realize their C compilers are billions of dollars of development, and they'd never be able to do it in the first place. A Forth on the other hand can be developed in a month (I'm being honest-to-god realistic here. A lot of people would say "a weekend", but let's be real, anything useful will be more than a weekend. I'm trying to convince you this isn't bullshit :)).

If you have any more questions let me know. I was bit by Forth about 2 years ago but had read about it long ago when I was like 16 and passed it off as too hard. It's the same shit as when FP took off: it's a different mental model, so it will take time to morph your mind.

Edit: read the larger comment below, and they are totally correct:

> most Forth tutorials today are written by people who don't really know Forth

One day I might write a small Forth novella teaching how to actually think about Forth programs. In these 2 years I've had to just practice and write programs to see common patterns or idioms - kind of exactly like when I was learning Haskell years ago.

Re: Easy Forth (2015)

#36
post #7

This has showed up here a few times before (example): https://news.ycombinator.com/item?id=10634918 I'm always interested in hearing people's reactions to Forth though and every now and then you get a cool new story on these threads, so I'm not complaining.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

Unfortunately we aren't in the 1980's glory days of Forth in 8 bit home computers, and many students don't know what HP-48GX stands for.

Re: Easy Forth (2015)

#37
post #19
post #7

Earlier quoted context omitted.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

As I like to say: "C is a language that solves a million problems. Forth is a million languages that solve almost nothing." :-P I've been reading about Forth for 30-40 years. The dual stack is easy to understand. My problem is that I cannot see how control flow works in Forth, e.g. a simple if-then-else. I think that something as fundamental as an if-then-else should be obvious in a useful language. Heck, it's obviou…

It's funny that you say that, because from my point of view, control flow in Forth is one of its strong points over assembly language, because it has properly nesting control-flow structures. The syntax is a little strange; the literal translation of

    if (siz != 0) *d = '\0';
is (untested)

    siz @ 0  if 0 d @ c!  then
when what you'd normally expect is something like

    if  siz @ 0  then  0 d @ c!  fi
but that's sort of a question of RPN. At least else comes where you expect it, even though that makes then even stranger; we can translate

    if (key key) {
      tree++;
    } else {
      tree = tree->right;
    }
literally as (untested)

    key @ tree ->key @ right @ tree !
    then
Now, if you were comparing Forth to Lua or C here, I would agree: this is far less obvious, in the sense that it's completely unfamiliar and requires you to learn Forth's idiosyncratic way of writing things. But in assembly language? GCC generates, in context, the following assembly code for the C if-else statement above:

    addhi r0, r0, #8
    bhi .L5
    ldr r0, [r0, #4]
    b .L6
This is using the flags from a preceding equality comparison, and the branch target labels are earlier in the enclosing loop. You can not tell me that this is "obvious" if you don't know ARM assembly!

From a certain point of view, Forth is just what you get if you take assembly language and look for the simplest way to add properly nesting expressions, properly nesting control structures, subroutines with arguments and return values, arbitrary compile-time computation, an interactive debugging environment, a scripting language, disk storage, and multithreading.

Re: Easy Forth (2015)

#38
post #36
post #7

Earlier quoted context omitted.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

Unfortunately we aren't in the 1980's glory days of Forth in 8 bit home computers, and many students don't know what HP-48GX stands for.

BASIC, especially the Microsoft dialect, became the dominant language for microcomputers because it would fit in a tiny space, e.g. 4k. For that matter it was big in the minicomputer age because it was used in multitasking systems that weren't that big. Circa 1980 my high school had a PDP-8 which had three terminals and could run a three user BASIC with just 32k 12 bit words.

There weren't a lot of languages which would fit in a tiny space, but FORTH was one of them. Like LISP it's a language where you can (1) implement the language without any kind of recursive parser and (2) write control structures in the language itself because each "word" in forth has both a run-time and compile-time interpretation.

Re: Easy Forth (2015)

#39
post #36
post #7

Earlier quoted context omitted.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

Unfortunately we aren't in the 1980's glory days of Forth in 8 bit home computers, and many students don't know what HP-48GX stands for.

RPL isn't Forth.

Re: Easy Forth (2015)

#40
post #33
post #7

Earlier quoted context omitted.

Right. And once again, you’ll also notice that no one is actually coding anything useful in Forth.

Every single coder that uses chaining operators is using concatenative programming concepts. Shell piping is also a form of concatenative programming. Just because you don't specifically use forth does not mean forth is dead.

Shell piping isn't Forth.
Post reply on HN