3 ms·
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
by vdupras 1y ago
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/ https://tumbleforth.hardcoded.net/ as such an eye-opening process. It's less "gentle" than Easy Forth here, but it digs deeper.
- bxparks 1y agoFrom the comments in this thread, it seems that to understand how Forth implements a simple IF-THEN-ELSE control-flow, I have to understand the difference between non-immediate and immediate words. I also have to understand the difference between outer and inner interpreter. And I have to understand how Forth generates snippets of machine code (where does that get stored? I thought Forth only has 2 stacks, does it also have a general heap?). Then understand how the THEN token goes back and patches the placeholder address generated by the IF token. And understand the difference between the parsing phase and the interpreted phase of the Forth interpreter/compiler. 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.
- vdupras 1y agoIt's fine, I can't force you in either. Maybe one day you'll dive into the subject. From the look of the comments here, you have all the hints you need.