It’s well worth reading through, even if you don’t know any assembly.
[1] https://github.com/nornagon/jonesforth/blob/master/jonesfort...
91–100 of 128 posts
It’s well worth reading through, even if you don’t know any assembly.
[1] https://github.com/nornagon/jonesforth/blob/master/jonesfort...
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,…
Perhaps someone will upload some Forth source code for a few larger systems e.g. "Fmacs", an Emacs-like editor written in mostly Forth with Forth instead of ELISP being the embedded language.
Then it would be interesting to compare speed and readability (important today and every day) as well as memory requirements in RAM and on disk etc. (not so important anymore, used to be very important in the past).
I had a look at the little Forth-based operating system's source code and of course couldn't comprehen much, which is obvious because looking at the code doesn't tell you, you need to imagine what's going on with the stack.
Earlier quoted context omitted.
>>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?
Forth was invented around 1970 for controlling equipment in an astronomical observatory, running on a PDP-11, a 16-bit computer with up to 64 Kbytes of memory. Its heyday was the 1970s and 80s, when it was mostly used for small embedded systems on 8- or 16- bit processors with 8 kb -- 64 kb of memory. It was possible to run an entire Forth development system along with the application on these small targets without r…
Earlier quoted context omitted.
This is fun! I was going to try to draw a circle but was missing sin/sqrt. Then I thought of using a lookup table but got stumped. Do you have any pointers for drawing a circle? I'm looking at demo #4 ( https://susam.net/fxyt.html#XYpTN1srN255pTN1sqD ) to see where the circular shapes are coming from. Have you seen Forth Haiku? https://forthsalon.appspot.com/
doesn't need to be accurate, could do something like this (distance + treshold) : https://susam.net/fxyt.html#XN128dXN128dpYN128dYN128dpsN4096... smaller with dup : https://susam.net/fxyt.html#XN128dDpYN128dDpsN4096lN255pC circles pattern : https://susam.net/fxyt.html#XDpYDpsN8qN3riN255pC PS: fun tool !
X^2 + y^2 > z^2 ? 1 : 0
Earlier quoted context omitted.
No, Bitcoin Script is not Forth. Bitcoin Script is designed to guarantee termination, so no Turing-complete programming language was permitted. Like BPF, Bitcoin Script doesn't have subroutine definitions or backward jumps, so each opcode executes at most once. This is like saying JSON is C++.
It's more like saying JSON is Javascript, which it is to a degree.
Earlier quoted context omitted.
Unlike most languages, Forth has two stacks. It sounds trivial, but it changes many things. It allows for a leaner call convention. With a single stack, every function call has to "shovel forward" its arguments over the function return address, where Forth "glides" through its arguments, making function calls significantly lighter.
> Unlike most languages, Forth has two stacks. Like Forth, Ada has two stacks. Unlike Forth, which uses two stacks to simplify the language, Ada uses two stacks to complexify the language. This generalizes to other language features.
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…
Glad to see Forth on HN today! For anyone who likes playing with small experimental projects, I once made a minimal, esoteric canvas colouring language inspired by Forth and Tixy: https://susam.net/fxyt.html
This is fun! I was going to try to draw a circle but was missing sin/sqrt. Then I thought of using a lookup table but got stumped. Do you have any pointers for drawing a circle? I'm looking at demo #4 ( https://susam.net/fxyt.html#XYpTN1srN255pTN1sqD ) to see where the circular shapes are coming from. Have you seen Forth Haiku? https://forthsalon.appspot.com/
Earlier quoted context omitted.
I will definitely look into that. If understanding this special IMMEDIATE mode is required to understand the Forth interpreter for something as fundamental as control-flow, it seems fair to say that Forth is not a simple language. It's not just an advanced programmable RPN calculator An RPN calculator has a program counter, which makes control-flow easy to understand. In comparison, C is a high level language, but th…
The mapping to assembly of: 42 = if ."hey!" then is much more straightforward than if (n == 42) printf("hey!"); I understand that to the newcomer, it might not appear that way, but implementing a Forth is really eye-opening in that regard. If I might allow myself a bit of promotion, I wrote https://tumbleforth.hardcoded.net/ as such an eye-opening process. It's less "gentle" than Easy Forth here, but it digs deeper.
But you are saying that the Forth version is simpler than C version which will kinda look like this after it's compiled (Z80 assembly code, it's in my head right now):
ld a, (variableN)
cp 42
ld hl, StringHey
call z, Printf
...
StringHey:
.db "hey!", 0
I find that hard to believe, but I accept that you believe that.Earlier quoted context omitted.
Ah I see, this is peeling back a few layers of obscurity about the Forth interpreter for me. Let's stick with a Forth interpreter because that seems easier to think about for me. Are you saying that the Forth interpreter is a 2-pass interpreter? Or does the interpreter go into a special IMMEDIATE mode upon hitting the IF keyword, then it just consumes subsequent tokens without doing any dispatching, until it hits the…
I've actually never worked with a "pure" interpreter in Forth, only compilers of various levels of complexity. Threaded code compilers are (in my experience) by far the most common way to deal with forth -- and they are very much 2-pass. Even when used as an "interpreter," they generate (trivial, usually) machine code, then jump to it. Consider a definition (in some ill-defined Forth variant) like : abs-sqr ( n -- |n…
Lots of good info, thank you. I don't think I will fully understand what you wrote until I implement a Forth interpreter myself.
So a side question: If most Forth "interpreters" are compilers, how does a Forth interpreter work in a Harvard architecture microprocessor (with separate memory space for data and instructions) instead of a Von Neumann architecture with a unified memory layout? In other words, in a Harvard architecture (e.g. AVR microcontrollers), the Forth compiler will live in read-only flash ROM, and it cannot generate machine code into RAM and execute it, because the data memory is not executable.