News for hackers. Stuff that matters.
Re:What the hell is Forth? (2019) by amalgamated_inc on Friday January 13, 2023 @03:31PM (#34373472)
I believe that any programmer should at least know a little about Forth. It's like Lisp. Just knowing about them is extremely enlightening, even if you don't use them in your daily life.
Re:What the hell is Forth? (2019) by seanw444 on Friday January 13, 2023 @04:00PM (#34373817)
I've also heard it cures cancer. Any truth to this?
Re:What the hell is Forth? (2019) by agumonkey on Friday January 13, 2023 @04:28PM (#34374135)
It can alleviate the symptoms of javadenomas
Re:What the hell is Forth? (2019) by amalgamated_inc on Friday January 13, 2023 @04:06PM (#34373872)
Results not in yet but it looks promising, yes.
Re:What the hell is Forth? (2019) by shrubble on Friday January 13, 2023 @05:17PM (#34374680)
The percentage of people with cancer who are Forth users is very low. Take that as you wish...
Re:What the hell is Forth? (2019) by vram22 on Friday January 13, 2023 @06:31PM (#34375369)
CHECK FACTH FIRTH YOUR
Re:What the hell is Forth? (2019) by vram22 on Friday January 13, 2023 @07:08PM (#34375700)
Downvoter prolly doesn't know Forth, and fifth, has no sense of humor :)
Re:What the hell is Forth? (2019) by seanw444 on Friday January 13, 2023 @07:31PM (#34375914)
I got downvoted. Humor is bad on Hacker News.
Re:What the hell is Forth? (2019) by buescher on Friday January 13, 2023 @07:54PM (#34376067)
Humor involves a point of view, and that's not allowed. Just ask ChatGPT.
Re:What the hell is Forth? (2019) by vram22 on Friday January 13, 2023 @07:07PM (#34375684)
Did you mean:

THIS TRUTH ANY TO?

Re:What the hell is Forth? (2019) by jll29 on Friday January 13, 2023 @04:20PM (#34374033)
Agree with the parent, it's a language worth knowing like LISP is worth knowing, but (unlike LISP) it is not a good language choice for almost all use cases in 2023 (almost all use cases are not that memory constrained any more, even embedded systems), for the same reason you shouldn't use Perl (it is very hard to read code).

I was going to say "its main disadvantage is that the only way to find out what a piece of code does is to execute it mentally" (non-declarative) but one may say that of every language to an extent. Instead I will say it feels like using a macro-assembler for a stack VM.

Clifford Stoll, author of "The Cuckoo's Egg", in which he described how he chased a hacker, allegedly used FORTH to control a radio telescope (https://www.amazon.co.uk/gp/product/1416507787) back in the days (not sure, I might have got this nugget from the book).

Re:What the hell is Forth? (2019) by slaymaker1907 on Friday January 13, 2023 @04:34PM (#34374196)
I don't know, I think it can be a pretty solid language depending on what variant you use. There are few pieces of code in Forth that make me think "man, this seems repetitive, but I don't know how to actually generalize this" because abstraction is little more than structured copy+paste.
Re:What the hell is Forth? (2019) by avmich on Friday January 13, 2023 @05:48PM (#34374981)
> abstraction is little more than structured copy+paste

Which perhaps is logical, since Forth is a concatenative language. Roughly, one can split a program in half at any point and get two subprograms which can be called one after the other - in the same order - to get the same result.

Like, to calculate 2 + 3 * 4 one would write 2 3 4 * + in Forth, this sequence can be split in two 6 different ways, and we can even meaningfully interpret those two parts each time. E.g. part 4 * + is a two-argument function which multiplies first (closest to the top in the stack) by 4 and sums the result with the other argument - in JavaScript it would be function(x, y) { return 4*x+y; }.

Re:What the hell is Forth? (2019) by pkaye on Friday January 13, 2023 @04:26PM (#34374105)
The original use for FORTH was to control radio telescopes.
Re:What the hell is Forth? (2019) by macintux on Friday January 13, 2023 @05:34PM (#34374852)
I was delighted (and saddened) when I discovered a Forth manual written by W. Richard Stevens for Kitt Peak observatory. A great writer lost far too young.
Re:What the hell is Forth? (2019) by mananaysiempre on Friday January 13, 2023 @05:30PM (#34374810)
I don’t really feel I can judge whether it’s good or not to use generally, but it’s difficult to obtain a similar degree of DSL-ness even on pretty powerful (e.g. Micropython-grade) constrained platforms. Forth, along with Lisp, is one of the original DSL substrates (Thinking Forth spends like half its pages on preaching EDSLs), and I don’t think it’s really been supplanted in that niche by anything that doesn’t require a beefy GC.

(The extremely easy bootstrapping from any point down to an ISA manual and a ROM programmer—or a monitor that accepts peek/poke/goto from a UART—I also don’t think has really been replicated anywhere else.)

Re:What the hell is Forth? (2019) by bob29 on Saturday January 14, 2023 @12:33AM (#34377620)
DSL just a library that exports a lot of functions that work together any language that allows naming functions does that?
Re:What the hell is Forth? (2019) by mananaysiempre on Saturday January 14, 2023 @05:47AM (#34379166)
If you don’t care about syntax convenience, yes. In practice, a(n idiomatic) Forth “library” can have an API like, for example,

  1000 ,bp) ax mov,
for laying down assembly code in memory (might look a bit unusual, but think “postfix assembler” and it’ll become natural soon enough). If you want this to compile down to just byte writes and arithmetic without requiring an assembler library at runtime (DynASM-style), you can do that as well.

Custom control structures[1], object systems, perfect hashing, parser generators, all that fun stuff that’s possible with flexible syntax and arbitrary compile-time code execution, people have done it. You never have to think whether an X-macro is sufficiently ugly yet to warrant a custom preprocessor. (If you want to say “web templating”, you can say “web templating”, except it’s not that pleasant with manual memory management, and most of what I’m thinking about was written in the 80s.)

There’s nothing impossible about this in any language (the absence of a competent C REPL continues to amaze me), but not all languages are good at everything they can technically do, and Forth is good at these.

(Forth is also bad at some things. If you want code that transparently works on floats and doubles, or 32- and 64-bit addresses, on the same system depending on a compile-time setting, it’s going to be painful. Passing abstract types by value is impossible to do elegantly as far as I know. Omitting unnecessary code from the executable, trivial with static libraries and a linker, requires adapting half your implementation and is a serious selling point for commercial Forth systems. And so on.)

[1] I know we’re all alleged adults and are not supposed to get excited about these, but does LuaJIT’s FOLD tree peephole optimizer, for example, qualify as a legitimate custom control structure? (It’s implemented with a combination of macro magic and a custom preprocessor.)

Re:What the hell is Forth? (2019) by SoftTalker on Friday January 13, 2023 @05:31PM (#34374825)
Perl doesn't seem like it should necessarily be hard to read (I'm not a perl programmer) but agree that most perl that I've seen is pretty opaque. I guess if you really get to know the idioms maybe it's easier.
Re:What the hell is Forth? (2019) by tmtvl on Saturday January 14, 2023 @01:44PM (#34382761)
I guess if you really get to know the idioms maybe it's easier.

It is, as long as you stay away from things like selfgol* or memowe's keywords only JAPH** (which is technically very readable, it's just very hard to comprehend).

* https://libarynth.org/selfgol ** https://www.perlmonks.org/?node_id=594266

Re:What the hell is Forth? (2019) by turtledragonfly on Friday January 13, 2023 @06:00PM (#34375103)

  > for the same reason you shouldn't use Perl (it is very hard to read code)
I slightly disagree with this take on Perl. Agreed that it is easy to write code which is hard for others to read, and agreed that it is often not a good idea in a large-team setting, for that reason.

But there is a lot of code that doesn't fall in that category, and Perl, by its nature (and by CPAN), can be remarkably good at just "getting stuff done" for oneself. All the wild syntax can really help in expressing a concept succinctly.

I wouldn't say the same about Forth, though.

Re:What the hell is Forth? (2019) by efitz on Friday January 13, 2023 @07:23PM (#34375830)
Someone told me once that Perl was write-only.
Re:What the hell is Forth? (2019) by jll29 on Saturday January 14, 2023 @06:22AM (#34379367)
Not trying to disparage Perl, which has some utility, like most languages, notably fast regex engine and presence on many systems.

BUT: I've been writing Perl for much longer than Python, but despite wanting to write readable/maintainable code, Perl has a tendency to get you to a stage where your code looks cryptic (part of it is by design - Larry Wall, a linguist, values implicitness as "context" - I think explicitness, by contrast, should be aspired to, in order to avoid confusion). I've never written cryptic Python code (and I am not a particular Python fan, as I prefer statically typed compiled languages), but it should be said that clarity is one of Python's advantages.

I agree with you that it is easier to write readable Perl than readable FORTH, which could be due to the similarity of Perl with other non-stack imperative languages.

Re:What the hell is Forth? (2019) by zelphirkalt on Saturday January 14, 2023 @08:09AM (#34380044)
Well, in Forth there isn't much "wild syntax" to begin with, so naturally you couldn't claim the same about Forth.
Re:What the hell is Forth? (2019) by jcpst on Friday January 13, 2023 @06:00PM (#34375111)
> it is not a good language choice for almost all use cases in 2023

I think I agree with this. But it’s fun to think about wild scenarios where it would make sense.

Like some dystopian future where people are trying to cobble found hardware together to make something.

Re:What the hell is Forth? (2019) by alexwennerberg on Friday January 13, 2023 @07:31PM (#34375915)
> Like some dystopian future where people are trying to cobble found hardware together to make something.

https://git.sr.ht/~vdupras/duskos

http://collapseos.org/

Re:What the hell is Forth? (2019) by jcpst on Saturday January 14, 2023 @03:44PM (#34384006)
Thank you!
Re:What the hell is Forth? (2019) by ArtixFox on Saturday January 14, 2023 @12:15AM (#34377555)
If a Forthlike language was to be made today, what features would it require to not be a hard-to-read mess? I can see some type of typesystem being useful, I dont know what else can make it better.
Re:What the hell is Forth? (2019) by t-3 on Saturday January 14, 2023 @05:39PM (#34384841)
Typing would make things more verbose, but not any more readable than just writing words for each type of data you're dealing with, which accomplishes the same thing. Forth can dictionary mask and forget words, so typed-lang-style overloading is trivial, but unnecessary.

Many short word names could be expanded from symbols and abbreviations suited for 4-character names into more verbose versions, but the underlying RPN stackiness would still prove an impediment to broad understanding.

Native vectorization like APL or Lisp would increase the base complexity of the language machinery and make implementation more complex, but would allow the language to be simpler by getting rid of the need for most stack reordering.

Re:What the hell is Forth? (2019) by amatic on Friday January 13, 2023 @05:17PM (#34374675)
I couldn't get jonesforth to compile correctly. Not sure why. I found a python and a javascript implementation, not sure if I like them. Any recommendations?
Re:What the hell is Forth? (2019) by anyfoo on Friday January 13, 2023 @05:42PM (#34374920)
Do you maybe want to tell us how exactly "not compile correctly" manifested?
Re:What the hell is Forth? (2019) by amalgamated_inc on Friday January 13, 2023 @05:28PM (#34374774)
I made tons of typos in both the assembly and Forth part when I did mine, but it did end up compiling correctly. Hunting the typos down was hard though because you get literally 0 feedback.
Re:What the hell is Forth? (2019) by gerdesj on Friday January 13, 2023 @07:01PM (#34375629)
A million errr 40 odd (my back is dim etc) years ago the end of year stuff (open day etc) was fast approaching. Our science teacher asked a few chaps (all boys prep school - Devon, UK) to have a go at showing off this computing thing or something, oh and I have this Forth thing on tape and this: ZX Spectrum. We'd graduated from ZX80s and 81s. We had 20 brand new Speccies newly bought. The Promised Land beckoned.

We cobbled together text whizzing smoothly across the screen and changing colours within about 20 mins of loading the thing. Loading from tape took a good five minutes. Unlike the C64 and Vic20 the Speccy used consumer tape units.

I have absolutely no idea what you are on about with your big boy modern programming terms but I managed to convince quite a few parents that their sprogs were at the cutting edge or at least wasting time well, back in the day!

Re:What the hell is Forth? (2019) by sramsay on Friday January 13, 2023 @10:08PM (#34377014)
> It's like Lisp. Just knowing about them is extremely enlightening . . .

I agree. My introduction to Lisp was Seibold's Practical Common Lisp -- a very hot book back in the mid-to-late aughties, that I suspect introduced a lot of people to Lisp.

Forth feels like it's having a similar moment (by which I simply mean: a lot of people are talking about it in terms of enlightenment, not that it's going to replace JavaScript!). So I wonder. Think someone will write a Practical Forth?