rotting bones wrote: ↑Sun Feb 12, 2023 1:34 pm
Travis B. wrote: ↑Sun Feb 12, 2023 12:42 pm
To me the reason Forth is less popular than it, well, ought to be is its tendency towards write-only code and its reputation for this. However, this is simple to solve - there are Forths such as gforth and my zeptoforth with support for block-scoped local variables, and IMO these, when actually used, really solve Forth's readability problems. Liberal usage of local variables greatly reduces the stack twiddling that bedevils more traditional Forths. From looking at my Forth code from before I added local variables to zeptoforth and my code afterwards the difference is like night and day; the latter code is infinitely more readable.
OTOH, I think the thing that people like to complain about, RPN, is much less of an issue in reality. Once you have local variables, it really is just like if you took Lisp, flipped the order of everything, and deleted all the parentheses. Once you are used to it it really is a non-issue.
I like Forth. When I wanted to try zeptoforth, you said something about niche hardware.
My understanding is that Forth is mainly used for low level coding. If I wanted to write a neural network in Forth, I might have to juggle millions of values on the stack. These values will have complex, structured relationships among themselves. My headache is coming back just thinking about it. Almost makes me want to try it. GForth has classes, doesn't it? Can I get GPU support? I don't suppose any Forth has AI libraries already?
As niche hardware goes, zeptoforth runs on RP2040-based boards (in theory it is dependent on the particular flash used, but no one I know who's tried it on an RP2040 board has not gotten in it to boot, even though the flash has better performance on some boards than others, and there are compatibility issues with LED support due to it being board-specific), and RP2040-based boards are cheap and plentiful at the present. I recommend getting one of these. It is known to run best on the Raspberry Pi Pico, for which RP2040 support was originally developed and which has very good flash performance, and boards which integrate a Raspberry Pi Pico such as the Cytron Maker PI PICO. However, it has been confirmed to work on the Seeed XIAO RP2040 and Seeed Wio RP2040, and because the the Seeed Wi RP2040 has an ESP8285 radio on it, and ESP8285 radio support is in the works at this very moment, if you want to try out WiFi support in the near future you might consider it. The main downsides of these are that they have poorer flash performance in practice than the Raspberry Pi Pico, and the Seeed XIAO RP2040 exposes very few pins. Do not bother with the Raspberry Pi PIco W, though, because it will be a while before its WiFi chip is supported, and there are key features of the Raspberry Pi Pico which do not work on it and will not work on it in the immediate future such as the LED (as the LED on the Raspberry Pi Pico W is tied to a pin on the WiFi chip, so it will not work until I develop a working WiFi chip driver).
zeptoforth runs on an number of STM32 boards as well. If you get these you probably will get an STM32F411 board such as the STM32F411 "Black Pill", which I was able to actually buy during the worst part of the Great Chip Shortage despite being STM32; it also unofficially supports the STM32F411 Nucleo 64, but you have to do a minor bit of hackery to really get it to work on there. It also runs on STM32F407, STM32F746, and STM32L476 DISCOVERY boards, which at the present are not cheap or plentiful at all.
About Forth being for low level coding, as I like to put it, Forth is what you get when assembly and Lisp love each other very much... It is what you want when you want direct access to the physical hardware yet have a REPL and be able to compile code on the fly all at the same time. In the case of zeptoforth, considering that it runs on embedded systems leads to low level coding unto itself. However, zeptoforth also has a wide variety of higher level constructs atypical of many Forths, ranging from a user-friendly module/namespace system (which uses traditional wordlists internally but abstract them away), to the aforementioned block-scoped local variables, to an object system and (if that is too heavyweight for you) structures, to lambdas and closures, to a fully-featured preemptive multitasker and intertask communication constructs such as semaphores, locks, channels, streams, etc. more typical of traditional RTOS environments, to optional heap and pool allocators (with support for multiple heaps if the user so desires), to lightweight "action" scheduler constructs for when tasks are just too heavyweight, to hashmap constructs, to SDHC/SDXC card and FAT32 support, and so on.
As for doing the kinds of high-level tasks you mention, there are higher-level PC Forths out there, and these often expose outside code via foreign function interfaces so if you are writing a program in Forth on a PC, you can call libraries such as SDL and OpenGL, or the AI libraries you mention, from within Forth. A good high-level (and mind you, very untraditional) Forth to take a look at is Retro. If you want to get really high-level, I would also consider taking a look at Factor - I would not consider Factor to be a Forth per se, but is is an RPN concatenative language with a lot of good high-level ideas and significant standard libraries. (Too bad most of the core developers of Factor got snapped up by a variety of companies once they completed their degrees...)