#BabelOfCode 2024
Week 2
Language: Forth
Confidence level: Low
PREV WEEK: mastodon.social/@mcc/113743302…
NEXT WEEK: mastodon.social/@mcc/113867584…
RULES: mastodon.social/@mcc/113676228…
So today's challenge looks *absurdly* easy, to the point I'm mostly just suspicious that part 2 will get hard. I figure this is an okay time to burn Forth.
I'm wanting to save Fortran for a week I can use the matrix ops. This puzzle looks suspiciously like part 2 will turn into a 2-dimensional array problem.
Questa voce è stata modificata (9 mesi fa)
Robin Green
in reply to mcc • • •mcc
in reply to Robin Green • • •mcc
in reply to mcc • • •I *think* I'm doing this in pforth, for the simple reason that gforth, uh, isn't maintained anymore it seems, and so got dropped out of Debian Testing (which I have now)? I *think* I'd be *happier* using RetroForth, which is a "modern" Forth, but I guess it's better to learn the standardized, ANS Forth first. Even though everyone hates ANS Forth? Including the inventor of Forth…?
My biggest fear is there appears to be no way to read numbers written in ASCII from a file. We're predating ASCII
Oblomov reshared this.
mcc
in reply to mcc • • •First problem I hit is comments don't work. The documentation specifically says text in parenthesis are comments, but it isn't accepted.
After some staring at the docs, I realize in all the examples, there are spaces. It turns out (Comment) is not a comment, but ( Comment ) is a comment. Because ( isn't a pure operator built in the language, rather there's a FORTH word ( that eats all words until ) is found. Holy crap. I never thought I'd say this but maybe it IS possible to self-host too hard
Oblomov reshared this.
sierra
in reply to mcc • • •AMS
in reply to mcc • • •Marc B. Reynolds
in reply to mcc • • •Kat Marchán 🐈
in reply to mcc • • •oh oh. If you’re still open to language ideas and you want to get a sense of what a forth-like language would feel like if it were “modern”: have you heard of factorcode.org ?
It’s as if Common Lisp, Smalltalk, Forth, and Haskell had an unholy union. It was developed by two of the Swift devs!
Factor programming language
factorcode.orgmcc
in reply to Kat Marchán 🐈 • • •sierra
in reply to mcc • • •mcc
in reply to mcc • • •So this documentation is kinda very bad!
Lacunae I have noticed:
- They define a `KEY` operator for taking a character from STDIN, but don't explain what happens if `KEY` receives an EOF (experimentally: I seem to get a -1?)
- They explain a special syntax `CHAR n` for inserting the ASCII value of n directly into the code, but don't explain how the fuck you're supposed to represent the ASCII value for a non-character symbol such as a space or newline
Oblomov reshared this.
mcc
in reply to mcc • • •More pforth documentation horrors
- The pforth tutorial is not a tutorial for pforth but rather a general forth tutorial, and therefore hedges itself frequently. For example, notice this section where it explains that "many forths" have a CASE statement. "Many forths"? What about THIS forth I'm reading the documentation to RIGHT NOW?
- ABORT not documented. The documentation lists it as a reserved word but not what it does
Oblomov reshared this.
Onairda, el Oripmav
in reply to mcc • • •Mark T. Tomczak
in reply to mcc • • •"Many Forths" is my favorite Madeline L'Engle book.
(Alternative joke: "Many Forths" is a pretty good newspaper comic)
james is here
in reply to mcc • • •the book to use for "I don't know enough Forth yet to understand this Forth" is Starting Forth forth.com/starting-forth/
The word to use for "I don't understand what this Forth system is doing with this word" is SEE, which disassembles the word into its components(and in more developed systems, goes all the way down to the assembly instructions). pForth does have SEE, fortunately.
Starting FORTH - FORTH, Inc
FORTH, Inc.mcc
in reply to james is here • • •mcc
in reply to mcc • • •Wrote a version 1.0 of my program, testing it. All I've got so far is the character parser, reading the numbers in and decoding ASCII and that's it.
This is… bad. I would describe this as bad behavior for a programming language interpreter
Oblomov reshared this.
mcc
in reply to mcc • • •The forth interpreter isn't completely busted, my test.f screenshot above worked. A simple "echo ascii values" program I wrote ( BEGIN KEY DUP . CR 0< UNTIL ) worked. But my 32 line, mildly more sophisticated program just… signal 11s. I do not know how to proceed. I am using "Debian Testing", which is TECHNICALLY a beta OS, so maybe the pforth is broken *subtly*. gforth isn't in dpkg. I don't… I don't know what to do next if the compiler crashes.
Maybe I ssh into a VPS and run gforth there? 🙁
✧✦Catherine✦✧
in reply to mcc • • •Hugo "Dark Satanic" Mills
in reply to mcc • • •Hugo "Dark Satanic" Mills
in reply to mcc • • •It's probably a stack underflow. That's where most of my segfaults come from.
I usually stick in a metric shitload of `.S` and see if the stack is actually what I think it should be, and where it might be underflowing.
mcc
in reply to Hugo "Dark Satanic" Mills • • •Hugo "Dark Satanic" Mills
in reply to mcc • • •Brian Campbell
in reply to mcc • • •cassie
in reply to Brian Campbell • • •Hugo "Dark Satanic" Mills
in reply to cassie • • •mcc
in reply to Hugo "Dark Satanic" Mills • • •Hugo "Dark Satanic" Mills
in reply to mcc • • •mcc
in reply to mcc • • •So here's my *current* code, which crashes in pforth:
github.com/mcclure/aoc2024/blo…
I run it in gforth:
cat "data/sample-2.txt" | gforth src/puzzle.f
I get:
in file included from *OS command line*:-1
src/puzzle.f:13: Interpreting a compile-only word
>>>BEGIN<<< ( Line )
Backtrace:
$7F5C6D55EB30 throw
Line 13 is indeed the word "BEGIN". According to the tutorial, that is how you open a UNTIL loop.
fuck the in What?
aoc2024/02-01-nuclear/src/puzzle.f at ec7ac2f3ad500d65e07dfeeee5877bf70a667c17 · mcclure/aoc2024
GitHubazul
in reply to mcc • • •control flow words like BEGIN, UNTIL, IF, ELSE, THEN, etc should only be used inside a word definition. they are "compile-only" words, can't be used in interpreter mode.
Some forths have ways to handle these, but it's not standard.
azul
in reply to azul • • •so, if you wrap the BEGIN loop in a word definition and then call it, you should be good to go.
: my-loop
BEGIN
...
UNTIL
;
my-loop
Cassandra is only carbon now
in reply to azul • • •mcc
in reply to Cassandra is only carbon now • • •azul
in reply to Cassandra is only carbon now • • •james is here
in reply to mcc • • •mcc
in reply to james is here • • •Genders: ♾️, 🟪⬛🟩; Soni L.
in reply to mcc • • •FORTH is basically a macro assembler. or uh, macro code generator, really. tho there is an "interpreter" that recognizes words and immediately executes them.
if you call certain words, it corrupts the interpreter state. so they can only be called from compiled words.
or at least that's how it used to be done. we don't know about modern forths.
Hugo "Dark Satanic" Mills
in reply to mcc • • •Most of the useful stuff for actual programming (like conditionals, loops) can only be executed once compiled. That's usually done with : to create a new word with the compiled code in it.
(Also, that code's massively non-idiomatic, with a massive C accent; The Forth way is effectively about building a DSL with words that you can use to solve your problem: I've seen it described as "language-oriented programming".)
mcc
in reply to mcc • • •Okay. So some updates.
It turns out loops (BEGIN..UNTIL) are a "premium" Forth feature and are only available inside functions. So I need to wrap the whole program in a : function ; . Well not the whole program, not the VARIABLEs, and I don't think you can nest the functions, and… never mind. I do the nest. New code:
github.com/mcclure/aoc2024/tre…
gforth fails with :
src/puzzle.f:38: Invalid memory address
I wrapped my program in a : run [code here] ; run . Line 38 is "run".
I'm still lost.
GitHub - mcclure/aoc2024 at 85890d80d89ebe82df779e20607f78cd4275f8db
GitHubmcc
in reply to mcc • • •mcc
in reply to mcc • • •clarity flowers
in reply to mcc • • •mcc
in reply to mcc • • •Okay. So this explains my segfault! I can now run in pforth.
xoxo.zone/@clarity/11378379402…
I accidentally wrote on one line `partial TRUE !` ; correct would be `TRUE partial !`. All variable assignments in Forth are done with pointer dereferences, so the wrong order was like trying to write to memory address TRUE (-1). It is as if C++ allowed you to write "true = x;" by accident instead of "x = true;" and write the address of x to 0x1
I am unblocked, but still can't do jack shit in gforth
clarity flowers
2025-01-06 22:35:11
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Jeff Forcier
in reply to mcc • • •William D. Jones
in reply to mcc • • •At least it's not the Compaq Portable I. It's the only vintage computing purchase I regret. The foam pads on the keyboard have rotted on almost all still-existing specimens. Mine too.
The KB requires 12V, and drops 7V through a linear regulator that becomes as hot as the sun if not attached to the combo heat sink/KB enclosure. I need to 3D print some broken KB parts. The PCB is warped; the KB randomly types characters.
I should probably sell it to someone who is willing to fix it.
Bill Ricker
in reply to mcc • • •I have fond memories of that device.
With the modem program that had p2p mode, we had work-from-home 3-4 days a week, could share patch-files MORE easily from home.
The Herc monitor wasn't my favorite.
4 colors, all of them shades & tints of orange.
But it was amazing for the day.
mcc
in reply to mcc • • •*kicking and throwing things*
The tutorial for pforth softsynth.com/pforth/pf_tut.ph… says if you want an ASCII constant you write: CHAR A
I want to print an A. I write CHAR A EMIT. I get:
A ? - unrecognized word!
INCLUDE error on line #18 , level = 1
CHAR A EMIT
^^^^^^
I write CHAR 'A' EMIT. This works. The documentation lies! The documentation lies!!
I'm getting unexpected results for .S. Wait, what results do I expect? Like ABORT, PFORTH DOCUMENTS .S EXISTS, BUT NOT WHAT IT DOES.
pForth - portable Forth in 'C'
www.softsynth.commcc
in reply to mcc • • •Oblomov reshared this.
rk: it’s hyphen-minus actually
in reply to mcc • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •UPDATE: I have found a Forth debugger of the type I was looking for, but it only runs in DOS
holonforth.com/debugforth.html
EDIT: Before anyone asks, no, the Compaq Portable III does not help here, it boots but we have no way to get data on or off of it
Debug Forth
holonforth.comDHeadshot's Alt
in reply to mcc • • •Brian Campbell
in reply to mcc • • •pforth has TRACE (this may not display well on Mastodon):
: ABCD CHAR 0 DUP . EMIT ;
ok
Stack<10>
TRACE ABCD
<< ABCD +0 <10:0> || CHAR >> ok
s
<< ABCD +4 <10:1> 0 || (LITERAL) 0 >> ok
s
<< ABCD +12 <10:2> 0 0 || DUP >> ok
s
<< ABCD +16 <10:3> 0 0 0 || . >> ok
s
0
<< ABCD +20 <10:2> 0 0 || EMIT >> ok
s
<< ABCD +24 <10:1> 0 || EXIT >> ok
s
Finished.
ok
mcc
in reply to Brian Campbell • • •Brian Campbell
in reply to mcc • • •Oh, this helps with understanding some FORTH idioms:
rickcarlino.com/2017/common-fo…
The square brackets are "Bring compiler into and out of immediate mode". That's kind of what I expected; you use them to run this command now, which is what's needed from CHAR because it's a function that will just grab the next character from input (after any spaces) and give you its ASCII value. So you need it run before compilation.
Parentheses are a valid part of a word name, and they are conventionally for a low-level implementation detail.
Common Forth Symbols and Idioms
rickcarlino.comBrian Campbell
in reply to Brian Campbell • • •OK, yeah, if I try in gforth, I get the behavior you're seeing; 'A' (or just 'A the closing quote is unnecessary) gives the character value.
This doesn't work in my version of pforth, where I need to use CHAR or [CHAR] if I'm in compilation context.
mcc
in reply to Brian Campbell • • •@unlambda CHAR 'A'
and
[CHAR] A
Do not do the same thing!! CHAR in compiled mode is dropping 82 on the stack and it's why my program is failing
mcc
in reply to mcc • • •Lawful Regime Change Now! 🇺🇦
in reply to mcc • • •Hmmm ... zForth is very simple, is written in C and has a "trace" option:
github.com/zevv/zForth
#Forth
GitHub - zevv/zForth: zForth: tiny, embeddable, flexible, compact Forth scripting language for embedded systems
GitHubmcc
in reply to mcc • • •Alright! Progress.
While I was on the bus, @unlambda looked it up and pforth *has* a symbol-by-symbol trace (it's called… TRACE). Unlike most things in pforth, *this* feature is well documented. Now it also requires me to use INCLUDE, which *isn't* documented, and which I couldn't get to work, but n/m, I just pasted the whole program into the terminal each time.
What I found: Remember me not getting `CHAR A` to work, and experimentally finding `CHAR 'A'` as substitute?
…It's not a substitute.
mcc
in reply to mcc • • •I jokingly referred to a Forth "premium" mode before. Non-jokingly, this is called "compiled" mode. Inside a function is "compiled"; outside is "interpreted". Apparently running CHAR in compiled mode puts the number 82 on the stack. Why? I don't know. That's ASCII "R". I don't get it. Then 'A' *separately* puts 64 (ASCII A) on the stack.
@unlambda also found the solution here: I need to say `[CHAR] A`. The brackets mean "use the interpreted-mode version, not the compiled-mode version". (1/2)
mcc
in reply to mcc • • •CHAR - CORE
forth-standard.orgmcc
in reply to mcc • • •mcc
in reply to mcc • • •azul
in reply to mcc • • •mcc
in reply to azul • • •I'd be very curious about that; are there any extant forths you have in mind that work this way?
I've talked to Ramsey Nasser who was trying to describe something about each word in a concatenative language being like a mapping from one stack state to another, and this means we can impose types on that stack transformation.
azul
in reply to mcc • • •for full static types, there is kitten: kittenlang.org/
and mirth (my project): github.com/mirth-lang/mirth
factor does do some stack depth checking but it doesn't have static type checking.
i don't know of anything more minimal & more forth-like, but then again type system is kind of a non-minimal addition and it always implies a redesign of the APIs because forth was not designed with type checking in mind.
GitHub - mirth-lang/mirth: Compiler for the Mirth programming language.
GitHubmcc
in reply to azul • • •mcc
in reply to mcc • • •Joe Groff
in reply to mcc • • •mcc
in reply to Joe Groff • • •Joe Groff
in reply to mcc • • •mcc
in reply to Joe Groff • • •prozacchiwawa
in reply to azul • • •CaptMorgan
in reply to mcc • • •mcc
in reply to mcc • • •Anyway here's my 45-line code for a harness that reads in lines of ASCII numbers and prints and dumps the stack after each.
github.com/mcclure/aoc2024/blo…
It's… awkward in places. It would have helped to have else-if, character literals for whitespace (like '\t' and '\r'), and a better story for complex boolean exps
(`DUP DUP DUP 9 = SWAP 13 = OR SWAP 32 = OR`. Ouch.) Parts feel nice and parts feel real bad.
I expect the ACTUAL PROGRAM will be a few lines long, and possibly only take mere minutes.
aoc2024/02-01-nuclear/src/puzzle.f at beba6adc719247e61123ad1be7d2339c4a6f7f22 · mcclure/aoc2024
GitHubmcc
in reply to mcc • • •So functions in ANS forth, as far as I can tell, can't have locally-scoped variables…
…but there's no restrictions on what characters you can put in a variable name, so I can just store the variables in paths *cackles evilly*
mcc
in reply to mcc • • •Examples of valid comments in ANS Rust:
( You )
( You can (not) redo )
( You (can not) advance )
Examples of invalid comments in ANS Rust:
(You)
( You can ( not ) redo )
( You ( can not ) advance )
Owen Nelson
in reply to mcc • • •mcc
in reply to Owen Nelson • • •@onelson Neither do I, Owen.
Neither do I.
mcc
in reply to mcc • • •mcc reshared this.
mcc
in reply to mcc • • •mcc reshared this.
Hugo "Dark Satanic" Mills
in reply to mcc • • •@onelson I don't think you can, because FORGET will forget everything after the definition you're forgetting as well. This may have... unintended consequences.
(The canonical data structure for the dictionary is a linked list; FORGET just rewrites the location of the head of the dictionary).
Owen Nelson
in reply to mcc • • •AN/CRM-114
in reply to mcc • • •mcc reshared this.
mcc
in reply to mcc • • •No, no, I'm sorry. I was fooled by my syntax highlighter. In testing with the actual pforth executable it appears literally all of the above examples are invalid uses of Forth comments except ( You ) .
( You can ( not ) nest comments. )
Owen Nelson
in reply to mcc • • •Owen Nelson
in reply to Owen Nelson • • •mcc
in reply to Owen Nelson • • •@onelson To summarize, in Forth, comments are any text between ( Parenthesis ) . However, there are two rules:
- There must be a space after the opening parenthesis, and a space before the closing parenthesis.
- Parenthesis may not be nested.
Owen Nelson
in reply to mcc • • •Karel P Kerezman
in reply to mcc • • •mcc
in reply to Karel P Kerezman • • •Karel P Kerezman
in reply to mcc • • •mcc
in reply to mcc • • •Bluh
github.com/mcclure/aoc2024/blo…
Well, it didn't take minutes. And it wasn't "a few" lines, it was 48, about the same length as the input code. But I will say once I was doing "forthy things" (pure computation) instead of stuff Forth's bad at (regular programming) it was way quicker, easier. It did occasionally feel like flying. Some of these lines have a real clarity to them.
It's now very important I don't try to do part 2 tonight. In fact, I shouldn't even read it, so I don't *reads it* dammit
aoc2024/02-01-nuclear/src/puzzle.f at 6d8de2b0517836c3dabcd39d9115de1a7643d8ff · mcclure/aoc2024
GitHubmcc
in reply to mcc • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •Variables, Constants and Arrays
FORTH, Inc.Tom Forsyth
in reply to mcc • • •The Alot is Better Than You at Everything
hyperboleandahalf.blogspot.comclarity flowers
in reply to mcc • • •mcc
in reply to clarity flowers • • •clarity flowers
in reply to mcc • • •mcc
in reply to clarity flowers • • •mcc
in reply to mcc • • •Oblomov reshared this.
mcc
in reply to mcc • • •So there's a keyword in Forth named CELLS and it's actually very useful, for a variable x it's like saying "x *= sizeof(void *);" which is something that would be *very* useful to have a shortcut in C but we don't have one, so in part 2 of my Forth program I'm finding myself writing lots of lines like
CELLS
CELLS
CELLS
and the thing I want to say is not completely coming together in my head but, I know I want to write a Forth program containing defined words WITHIN and INTERLINKED
Uli Kusterer (Not a kitteh)
in reply to mcc • • •What is this keyword good for? Only use I can think of is for pointer arithmetics, but there C does that implicitly.
I.e.
int * foo = &bar;
foo += 2;
// foo has now had 2 * sizeof(int) added to it.
Am I misunderstanding what this does?
mcc
in reply to Uli Kusterer (Not a kitteh) • • •@uliwitness Forth doesn't do it implicitly.
a[4] in C, in Forth would be
a @ 4 CELLS + @
Riley S. Faelan
in reply to mcc • • •The catch is, unlike Forth (or BCPL), C doesn't have a single 'cell' size.
For a while, people thought they would be able to get away with 16-bit cells. Then, larger computers came around.
For a while, people thought they would be able to get away with 32-bit cells. Then, larger computers came around.
For a while, people thought they would be able to get away with ...
Alaric Snell-Pym
in reply to Riley S. Faelan • • •Riley S. Faelan
in reply to Alaric Snell-Pym • • •@kitten_tech But if your Common Pointer and Common Integer have different sizes, there's no platform's cell size.
@mcc
mcc
in reply to Riley S. Faelan • • •Alaric Snell-Pym
in reply to mcc • • •Riley S. Faelan
in reply to Alaric Snell-Pym • • •@kitten_tech On i8086, a common integer is 16 bits, but a common (full) pointer is 32 bits.
@mcc
mcc
in reply to Riley S. Faelan • • •@riley @kitten_tech it seems like we are describing to you the way Forth works and you are responding by providing arguments as to why the way Forth works is a bad idea. But this does not help as the way Forth works is the way Forth works.
I assume if the Forth standard fundamentally doesn't work on an architecture, the implementor simply violates the standard. Certainly every Forth implementation I've used so far violates the standard.
mcc
in reply to mcc • • •Alaric Snell-Pym
in reply to mcc • • •DPANS94
www.taygeta.comRiley S. Faelan
in reply to mcc • • •No, I'm explaining why the abstraction of 'cells' doesn't make sense in a C-like language.
(But BCPL, the Dawn C, did have it. Its cell was whatever the word of its target machine was.)
@kitten_tech
mcc
in reply to Riley S. Faelan • • •Oblomov reshared this.
Riley S. Faelan
in reply to mcc • • •There have been a bunch of weird machines with weird and/or variable pointer sizes. (Such as i8086's far pointers and near pointers.)
If you don't care about them, you might want to either define a macro such as
PTR_SIZEof your own, possibly assizeof(intptr_t). (Which is not the size of an integer pointer, but the size of an integer that is big enough to also fit a full pointer.)@kitten_tech
Riley S. Faelan
in reply to Riley S. Faelan • • •Although, there's, perhaps, some philosophical difficulty in what a 'full pointer' means in a system that doesn't, like i8086, shorten pointers, but extends them, with, say, a memory bank index.
@kitten_tech
mcc
in reply to mcc • • •Okay!
github.com/mcclure/aoc2024/blo…
That was rewarding in ways I did not expect and also deeply painful in ways I did not expect, ending with a not-that-long but nonetheless grueling debugging session at the end when I felt very emotionally Done, but had One Last Bug (the bug: "DUP 1+" should have been "1+ DUP", an error that would have been easy to catch with… variable names).
Final ratios
App code — 53%
<=> — 4%
Clone and restore stack — 28%
Load numbers from stdin — 15%
47% coulda been stdlib.
aoc2024/02-02-nuclear/src/puzzle.f at 08dc78e8705e4690082d4efcd85612c25064fbf8 · mcclure/aoc2024
GitHubmcc
in reply to mcc • • •Final Forth observations:
1. Something that a lot of people kept telling me when I was having problems/segfaults with Forth is I should think of Forth "like a macro assembler". Well, that's clearly not true, as doing this in assembly would have taken a fraction of the time. You know why? BECAUSE ASSEMBLY HAS REGISTERS. I did find myself wondering what Forth with registers would feel like; I strongly suspected *that* language, whatever it is, I'd enjoy more than Forth.
Paul Khuong
in reply to mcc • • •mcc
in reply to Paul Khuong • • •Paul Khuong
in reply to mcc • • •mcc
in reply to mcc • • •Matthew Loxton
in reply to mcc • • •I tried Forth on the Sinclair Spectrum in 1983, but it was seriously slow and clunky
I can't recall encountering anything ever being written in Forth
@TomF
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Alternately, because what's the point of this if I'm not amusing myself, I could intentionally arrange things so I do puzzles 1-24 in languages I've never¹ used and then write the 25th puzzle solution in Rust, like dunking a basketball.
¹ Incidentally, I am counting AppleSoft BASIC in this list despite my extensive use of the language when I was 6-7, because at that time I didn't know enough of the language for it to be turing-complete, meaning it was arguably not a programming language.
EOM
Roger BW 😷
in reply to mcc • • •mcc
in reply to Roger BW 😷 • • •Roger BW 😷
in reply to mcc • • •mcc
in reply to Roger BW 😷 • • •Andrew Richards
in reply to mcc • • •mcc
in reply to mcc • • •13 The optional Locals word set
forth-standard.orgmcc
in reply to mcc • • •By the way I am taking this week off from Babel of Code but! There's actually a second contestant, @unjello , doing the challenge at the same time/pace. Here are his threads:
Week 1: Microsoft Macro Assembler (1981 - 1991) mastodon.gamedev.place/@unjell…
Week 2: WATCOM C++ (1988 - present) mastodon.gamedev.place/@unjell…
Andrzej Lichnerowicz (@unjello@mastodon.gamedev.place)
Gamedev MastodonMeg
in reply to mcc • • •@TomF I'm kind of confused by this? The 6502 definitely has registers, and while it doesn't have many you can also use the "zero page" as kind of a very large pseudo-register file.
At any rate I think you'd still be happier writing a game in assembly on the 6502. Writing a game in forth sounds like hell.
mcc
in reply to Meg • • •mcc
in reply to mcc • • •Howard Chu @ Symas
in reply to mcc • • •mcc
in reply to Howard Chu @ Symas • • •Tom Forsyth
in reply to mcc • • •@hyc @megmac I get what you're saying, and I think I agree.
The other way to say it is that the 6502 is not unduly crippled by programming it in Forth versus assembly or C.
Whereas e.g. on the Z80, a simple Forth implementation doesn't use half the registers, so the temptation is to try to do a clever compile to map the top few items in the stack to those registers, which gets very ugly. Thus, the perf penalty of Forth-vs-asm is higher on these CPUs.
slembcke
in reply to mcc • • •@hyc @megmac @TomF I think the distinction I would make is that in 6502 asm you can do ex:
lda x_pos
add x_vel
sta x_pos
Which while it technically only uses one register, gives you a bunch of named locations that you can use like registers even if they are just global variables. My experience with globals in forth is that they are really confusing to use correctly.
Andrew Richards
in reply to mcc • • •Benjohn
in reply to mcc • • •Karl Oscar Weber
in reply to mcc • • •fabiosantoscode
in reply to mcc • • •Roger BW 😷
in reply to mcc • • •slembcke
in reply to mcc • • •Your devotion to AoC-ing with defunct old languages is a bit of a inspiration.
I’ve thought about doing similar before, but obviously never followed through. 🤔
mcc
in reply to slembcke • • •jhamby
in reply to mcc • • •@slembcke I'm curious what you might say about Ada 2022 (or 2012). For extra credit, GNAT supports SPARK 2014 mode, a subset of Ada 2012 for high-integrity software that lets you use "GNATprove" to statically verify your contracts and bounds.
en.wikipedia.org/wiki/SPARK_(p…
The version of GNAT built by distros doesn't have all the features, but there's a community version with a cargo-like package manager.
adacore.com/community
AdaCore also supports an IDE, written in Ada, called GNAT Studio.
Community
AdaCoremcc
in reply to jhamby • • •Lawful Regime Change Now! 🇺🇦
in reply to mcc • • •The exact "syntax" of that Forth comment construct is that the first "( " - a left paren followed by a space - starts the comment and the first right paren ends it.
So "(You" does not start a comment. "( You can ( not )" starts with the "( " and ends with the ") after "not ". The Forth parser is quite primitive and there are some undefined cases. MOAR FOOTGUNS.
mcc
in reply to Lawful Regime Change Now! 🇺🇦 • • •Howard Chu @ Symas
in reply to mcc • • •Man aging with style
in reply to mcc • • •Rhialto
in reply to mcc • • •Seitan Lu Linvegan
in reply to mcc • • •mcc
in reply to Seitan Lu Linvegan • • •Seitan Lu Linvegan
in reply to mcc • • •mcc
in reply to Seitan Lu Linvegan • • •mcc
in reply to mcc • • •Seitan Lu Linvegan
in reply to mcc • • •Try retro, it's really quite nice. It's as if forth and ruby had a baby, the docs are well written, there's lots of examples out there. I find it's easier to wrangle than gforth and the likes(esp when dealing with files, argh), it's a bit more modern, the runtime is minuscule. You can read Starting Forth, and follow along with most basic examples with Retro.
Factor is not .. unbroken. But it's an altogether different thing, it's functional programming, so it's more like lisp, and it's really kind of a mess(docs are broken, IDE will randomly close, lots of the examples don't work with the latest version), I tried it a few times, it wasn't for me. Although, its arity checker is really useful when learning about RPN programming for the first time.
Uiua is very interesting but not a forth, if you're interested in going down that route, I'd go for BQN first, then go back to Uiua.
Uxn is not going to help you here, it's a little bit like forth but everything will feel like absolute sheer pain coming from algols, I'd stick to the bigger languages, for learning at least.
Dag Ågren ↙︎↙︎↙︎
in reply to mcc • • •Howard Chu @ Symas
in reply to mcc • • •Dan Cassidy 🦌
in reply to mcc • • •mcc
in reply to Dan Cassidy 🦌 • • •Dan Cassidy 🦌
in reply to mcc • • •Pendell
in reply to mcc • • •Tom Forsyth
in reply to mcc • • •Sadly the only good reason to use Forth is if you're writing a compiler for it - because it's incredibly simple to do that. I like it for that reason.
Actually trying to get things done in it - I would rate that as significantly worse than just writing raw assembly.
Oblomov reshared this.
Ted Mielczarek
in reply to mcc • • •mcc
in reply to Ted Mielczarek • • •Joe
in reply to mcc • • •lambdageek
in reply to mcc • • •Σ(i³) = (Σi)²
in reply to mcc • • •Steve Leach
in reply to mcc • • •Weekend Editor
in reply to mcc • • •Greenspun's 10th Law:
Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
Of course, for some people Forth is an alternative.
en.wikipedia.org/wiki/Greenspu…
Computing aphorism
Contributors to Wikimedia projects (Wikimedia Foundation, Inc.)Duke Thinred IV
in reply to mcc • • •There are at least two clues here as to how long ago that was!
a colony of eukaryotes
in reply to mcc • • •mcc
in reply to a colony of eukaryotes • • •Cowboy Who?
in reply to mcc • • •- YouTube
youtu.beBrian Campbell
in reply to mcc • • •Huh, weird:
$ pforth
PForth V21
pForth loading dictionary from file /usr/lib/pforth/pforth.dic
File format version is 8
Name space size = 120000
Code space size = 300000
Entry Point = 0
Little Endian Dictionary
Begin AUTO.INIT ------
CHAR A DUP . EMIT
65 A ok
Stack<10>
Brian Campbell
in reply to Brian Campbell • • •Oh, and your changed version does not:
CHAR 'A' DUP . EMIT
39 ' ok
Stack<10>
mcc
in reply to Brian Campbell • • •mcc
in reply to Brian Campbell • • •@unlambda *sigh* this is about compile context vs inteprpreted context it turns out.
CHAR A EMIT CR A
ok
Stack<10>
: abcd CHAR A EMIT CR ; A ? - unrecognized word!
Stack<10>
THROW code = -13
Undefined word!
Why would that be a difference!!!
mcc reshared this.
Brian Campbell
in reply to mcc • • •Oh, wow:
: foo CHAR A DUP . EMIT ;
FOO already defined.
A ? - unrecognized word!
: abcd CHAR A DUP . EMIT ;
A ? - unrecognized word!
: ABCD CHAR 'A' DUP . EMIT ;
'A' ? - unrecognized word!
: ABCD [CHAR] A DUP . EMIT ;
ok
Stack<10>
ABCD
65 A ok
Stack<10>
I don't understand why, but you need to wrap CHAR in square brackets. Found here: forth.com/starting-forth/1-for…
Data and the Forth Stack
FORTH, Inc.mcc
in reply to Brian Campbell • • •@unlambda WHAT
also although it accepts CHAR 'A' it does NOT accept CHAR '\t'
Brian Campbell
in reply to Brian Campbell • • •Oh, starting to come up with a mental model that might explain this: Forth is interpreting tokens as you see them; pushing values to the stack, popping them from the stack when a command consumes them and pushes results to the stack.
But special keywords like CHAR instead do something different; they put the parser in a different mode, that consumes later symbols. So for example, : puts it in a mode that consumes later symbols to define a new word.
But in compilation mode, these special symbols don't work. The compiler would understand the value 65, but it doesn't run the CHAR command to consume a next value; it wants to compile a value that's already there.
The square brackets then say "no, actually I want you to execute this special command before compiling, don't try to compile it".
I'm learning this along with you, so I'm forming the mental model as we go and might be wrong, but I feel like that might be what's going on.
mcc
in reply to Brian Campbell • • •Lawful Regime Change Now! 🇺🇦
in reply to mcc • • •GitHub - philburk/pforth: Portable Forth in C
GitHubティージェーグレェ
in reply to mcc • • •Hold up, what?
I was reading along and thinking I too was cut from a similar clothe from the folks who were doing asm coding on 8bit CPUs back when I was doing Forth stuff in the 1980s.
But I am head scratching now: why do you need a modem so you can hack your N64?
What kind of N64 hacking are you planning to do that wouldn't be better facilitated by something like a Krikzz flashcart (since it's the 21st century) or if going more retro with something like a Dr. V64 (whoa CD-R drive!) or Bung Dr. V64Jr. (whoa up to 512MBits of RAM depending on the model and way too many AA batteries that still benefit from having a power supply plugged in too!)? There was that other Mr. Backup Z64 with different Endian choices too.
I mean, maybe there was an N64 modem too (was there? I don't remember anymore) but generally an EPP/ECP parallel port was more than sufficient for tools contemporaneous with N64 "scene" stuff.
mcc
in reply to ティージェーグレェ • • •@teajaygrey
1. cturt.github.io/shogihax.html
2. I am going to be getting the Analogue 3D analogue.co/3d . This is not a perfect reproduction of the N64, so first off I do not know yet which flashcarts will be compatible, so I can't currently get one; and second off I am VERY CURIOUS whether the modem exploit works (i.e.: i want to use the modem exploit to test if the Analogue 3D is "bug compatible")
3D - Analogue
www.analogue.coティージェーグレェ
in reply to mcc • • •Whoa!
TIL: "Morita Shogi 64, the only official N64 game to include a modem built-into the cartridge to support its unique online-play functionality"
(Now I am wondering, was there any "unofficial" N64 hardware with modems built into the cartridges? Similar to how there was the official SEGA Ethernet module for the Dreamcast, but there were also unofficial Dreamcast Ethernet hardware [which typically could only be used with specific things like NetBSD because they used different chip sets than the official SEGA one IIRC]).
Let us know how #2 goes! The Analogue stuff is kind of interesting to me, sort of; but mostly only their PCエンジン stuff and lucky me, I still have a SuperGrafx, a TurboExpress, a Core GrafxII and some sundry other NEC originals for such things and don't need to worry about bug compatible FPGA reproductions.
For some reason my mind is now gravitating towards making the comparison that Analogue is sort of like the Behringer for video game consoles. I used to have a very low opinion of Behringer, but given what after market prices for original synthesizers are these days and that they're producing contemporary clones of things like the LinnDrum, maybe more recent clones aren't so bad? (They were certainly pretty bad back in the day when such hardware was being contemporaneously produced and sold though).
Jay
in reply to mcc • • •Richard S. Westmoreland
in reply to mcc • • •azul
in reply to mcc • • •skimming through the code:
partial TRUE !
is writing to the memory address TRUE, it should be TRUE partial !
also the conditionals seem wrong, e.g. this isn't doing what you think:
DUP DUP DUP 9 <> 13 <> 20 <> AND AND
clarity flowers
in reply to mcc • • •azul
in reply to clarity flowers • • •Genders: ♾️, 🟪⬛🟩; Soni L.
in reply to mcc • • •Tom Forsyth
in reply to mcc • • •💻 okflo 🤸
in reply to mcc • • •Starting FORTH - FORTH, Inc
FORTH, Inc.Hugo "Dark Satanic" Mills
in reply to mcc • • •I'm guessing (I haven't tried it) that `CHAR n` will take *any* character that's written after the CHAR, other than space (or possibly newline) and give you the ASCII code for it.
That is, CHAR parses the next word for itself and works on that. (Much like `"` and `(` do).
Just a guess, though.
mcc
in reply to Hugo "Dark Satanic" Mills • • •Hugo "Dark Satanic" Mills
in reply to mcc • • •Hugo "Dark Satanic" Mills
in reply to Hugo "Dark Satanic" Mills • • •DPANS94
pages.cs.wisc.edumcc
in reply to Hugo "Dark Satanic" Mills • • •clarity flowers
in reply to mcc • • •Bill Ricker
in reply to mcc • • •Yes, Forth has even less inherent global syntax than Lisp.
This can be very good or very bad!
Tokenizing is very very simple. Space Tab Newline can't be part of a word, so a word is whatever jumble is between whitespace.
Contrary to every instinct formed by all prior experience,
special characters interspersed in a string of letters or numbers is not an expression to be further handled by the tokenizer, is a single word.
Which for an embedded bootstrap is fine.
Man aging with style
in reply to mcc • • •." This is a string."
."This is not a string"
Steveg58
in reply to mcc • • •наб
in reply to mcc • • •#1067376 - gforth: FTBFS: make[1]: *** [Makefile:655: build-libcc-named] Error 1 - Debian Bug report logs
bugs.debian.orgнаб
in reply to наб • • •#1039051 - RFA: gforth -- GNU Forth Language Environment - Debian Bug report logs
bugs.debian.orgmcc
in reply to наб • • •наб
in reply to mcc • • •Fish Id Wardrobe
in reply to mcc • • •💻 okflo 🤸
in reply to mcc • • •Factor programming language
factorcode.orgBaffinSquid
in reply to mcc • • •mcc
Unknown parent • • •cassie
in reply to mcc • • •mcc
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •@AlgoCompSynth Given the specific problem, I have trouble imagining what the thing I'd file is 🙁
I got gforth, it's in ubuntu
mcc
Unknown parent • • •@multisn8 I don't know what modifies the stack or doesn't. BECAUSE THE DOCUMENTATION LIES TO ME.
However, you would expect print statements to modify the stack because they consume their own arguments.
mcc
Unknown parent • • •Lawful Regime Change Now! 🇺🇦
in reply to mcc • • •Probably not. The whole "core" word set is very poorly factored. There have been some efforts by the standards committee to "make it make sense" but it doesn't. You just have to remember what happens.
If you want to read the standard, it's here: forth-standard.org/standard/wo…. But TBH you're better off working though "Starting Forth" and then reading the standard.
Forth Standard
forth-standard.orgmcc
in reply to Lawful Regime Change Now! 🇺🇦 • • •mcc
Unknown parent • • •Lawful Regime Change Now! 🇺🇦
in reply to mcc • • •Starting Forth is much better written, but it describes a typical threaded code implementation, not the supposedly more abstract language the standard attempts to specify. The standards process has been going on since 1979, when things were pretty much low-level machine-code implementations. It's a thankless job, trying to turn Forth into an abstract computer science object.
uxn makes more sense; so does 6502 assembly language.
mcc
Unknown parent • • •Lawful Regime Change Now! 🇺🇦
in reply to Lawful Regime Change Now! 🇺🇦 • • •Lawful Regime Change Now! 🇺🇦
in reply to mcc • • •mcc
Unknown parent • • •mcc
Unknown parent • • •