2023-05-01 06:24:06 Completely new to Forth, but I ended up spending this last weekend carefully going through jonesforth. 2023-05-01 06:26:45 The sheer parsimony of the Forth kernel (terminology?) is quite beautiful. 2023-05-01 06:27:22 And miniforth managing to fit itself in the MBR is super cool. 2023-05-01 06:30:44 Anyway, I definitely do want to try my hand at a Forth implementation. Just need to pick some interesting piece of hardware. 2023-05-01 06:31:53 I recommend reading Starting Forth and doing a little programming in Forth before writing one 2023-05-01 06:32:12 Just to help with the design a little, you can certainly write one without knowing Forth, but should you? 2023-05-01 06:33:04 A lot of us here have written our own Forths, it's a sort of rite of passage for some people, but not necessary by any means 2023-05-01 06:33:47 And there are some very experienced forthers who haven't written their own 2023-05-01 06:33:56 Yeah, I'm also curious about the user end as well. Implementing and using are probably pretty orthogonal, no? 2023-05-01 06:34:15 Not in Forth 2023-05-01 06:35:06 Forth tries to make friends with both the user and the machine equally. A lot of Forth programming relies on aspects of how your particular Forth environment is written 2023-05-01 06:35:12 or how it integrates into the given machine 2023-05-01 06:36:27 One of the big advantages of Forth is being able to read and understand your Forth environment, patch or change it when necessary, extend it, etc 2023-05-01 06:36:42 It's not realistic for most languages, but it's pretty much expected for Forth 2023-05-01 06:37:39 That's pretty slick. So it's pretty standard to munge the compiler and/or interpreter to fit domain-specific problems? 2023-05-01 06:39:03 It's not *that* common but if you have e.g. an embedded Forth controller then you'd probably centre everything around its job 2023-05-01 06:39:19 Possibly generating a sort of DSL for it 2023-05-01 06:39:37 Or if you had a custom forth for it you might change some of the rules that people usually have to fit the application 2023-05-01 06:40:16 What are some canonical High Quality™ Forth sources that would be worth studying for learning standard idioms, techniques, and architectural/design patterns? 2023-05-01 06:40:40 What I will say is that often Forth is described as a "DSL generator", but really in practice I think much of what that means is that regular Forth *can* look very DSL-like and like plain english 2023-05-01 06:40:54 But you don't necessarily need to write like that 2023-05-01 06:40:56 Do what works 2023-05-01 06:41:48 xelxebar: I think you can read anything in Forth and learn. The styles vary so much that you will ignore stuff you dislike and learn things you like 2023-05-01 06:42:52 I think Starting Forth contains the beginnings of good style, personally. 2023-05-01 06:43:47 And if you share your forth code people will suggest improvements 2023-05-01 06:43:53 Okay. I did quickly blast through Starting Forth. It's a bit verbose, but maybe I should study it more closely. 2023-05-01 06:44:36 Yes it's not everyone's style of writing, but maybe look at some of the longer programs in it 2023-05-01 06:44:58 You don't need to match that style but it's a good starting place, a lot of forthers started there 2023-05-01 06:45:16 Bear in mind Brodie wrote that before he had even done much programming 2023-05-01 06:45:33 So it's not gospel but it's highly influential 2023-05-01 06:47:14 My personal advice is to try and avoid making things flexible, generic, local, etc. Forth is best when you dive directly at the problem and apply "YAGNI" as much as possible. 2023-05-01 06:50:14 That's one of the tendencies I'm trying to retrain in myself. 2023-05-01 06:52:12 Starting Forth's section on double numbers in chapter 7 of the 1st ed pdf is worth reading more closely 2023-05-01 06:52:21 If you want to do engineering/scientific calculations using fixed point 2023-05-01 06:52:25 Creating towers of abstraction, internal to projects, is a strongly ingrained trait in whatever slice of SE I see at work. 2023-05-01 06:52:58 Then Forth might be a good exercise for you 2023-05-01 06:53:14 Not that everything needs to be minimal, but that I think it's good to understand the actual tradeoffs going either way 2023-05-01 06:57:24 About the only project idea I have right now is kind of hare-brained: an APL interpreter. 2023-05-01 06:58:03 Might be fun to play around with implementing UTF-8 support. 2023-05-01 06:59:59 Would need to make the tokenizer also word-split any characters outside the ASCII range. 2023-05-01 07:00:24 Okay. What implementation do you recommend starting off with? 2023-05-01 07:00:47 I've just been using gforth, I don't think it's that good but it's easy for everyone to get 2023-05-01 07:00:57 Jonesforth keeps segfaulting on me, but I'm moderately hesitant to jump all the way to gforth. 2023-05-01 07:01:15 Also the version of gforth available on most distros is very out of date, although really it doesn't matter too much 2023-05-01 07:02:54 If you stick to the ANS stuff you can port easier https://www.taygeta.com/forth/dpans.html 2023-05-01 07:02:58 Looks like my distro has 0.7.3, which appears to be the latest. The info manual for it is *huge*, though, which feels kind of antithetical to the spirit of Forth. 2023-05-01 07:03:15 Do yourself a favor and assume that 1 CHARS is 1, and also that your forth will not be case sensitive 2023-05-01 07:03:32 Because pretty much all forths are case insensitive or let you change the sensitivity 2023-05-01 07:03:43 0.7.3 is over a decade out of date I believe 2023-05-01 07:03:44 This looks fun: https://dacvs.neocities.org/SF/SForth220711dmp.txt. A forth in hand-written x86-64 opcodes, not even assembly :P 2023-05-01 07:04:38 Wait, what? https://gforth.org/ says that 0.7.3 is the latest. Website is just super old? 2023-05-01 07:04:56 It's the latest 'release' but there are snapshots going all the time in between 2023-05-01 07:05:10 Hahaha. Fun. 2023-05-01 07:05:16 They have been working towards 1.0, and haven't done an official release in years 2023-05-01 07:05:33 I find I need gforth 0.7.3 installed to build the new snapshots as well 2023-05-01 07:05:38 This smithforth implementation looks somewhat similar to some hand-written elf stuff I've done before. 2023-05-01 07:06:23 He's got videos apparently, might be worth watching 2023-05-01 07:06:31 veltas: Hrm. Where's the gforth repo? The savannah url on that website is 404ing on me. 2023-05-01 07:08:02 https://www.complang.tuwien.ac.at/forth/gforth/ 2023-05-01 07:08:16 That's the official website, they have a gforth.org website but it looks out of date 2023-05-01 07:08:32 Don't get me started on their housekeeping :P 2023-05-01 07:11:37 It's not great, but xkeyboard-config is somewhat similar, despite being used virtually everywhere :P 2023-05-01 07:11:53 any idea what editor/assembler Dave Smith used while writing that code? 2023-05-01 07:13:07 He says he used vi 2023-05-01 07:13:12 (probably vim) 2023-05-01 07:13:13 (i'm hoping there's a decent interactive assembler behind this) 2023-05-01 07:13:18 https://www.youtube.com/watch?v=9MSJGzYELBA 2023-05-01 07:13:28 No there isn't, he didn't use an assembler 2023-05-01 07:13:42 And the "assembler" is just xxd: cut -d'#' -f1 SForth.dmp | xxd -p -r > SForth 2023-05-01 07:15:03 In my opinion an assembler isn't really a 'dependency' compared to his code because I, too, can convert mnemonics to opcodes by hand. I just don't usually want to. 2023-05-01 07:16:49 agreed, i wrote a shell script to assemble single 8086, 80186, and 80286 instructions for this purpose 2023-05-01 07:17:59 This guy's channel is a good find xelxebar, he's got some interesting projects 2023-05-01 07:18:13 Like a Forth spreadsheet program 2023-05-01 07:19:29 It looks like he's having fun writing all these things in weird ways, I can't fault him for that 2023-05-01 07:19:38 And it's interesting to watch from afar 2023-05-01 07:20:12 I don't think I'd do anything he's doing the way he's doing it 2023-05-01 07:23:49 This is almost fine honestly, but I would probably render in terminal, and use a block (or one line of a block) for each cell https://www.youtube.com/watch?v=if1Psu6RJbs 2023-05-01 07:24:09 I like the ideas, I might do something inspired by that at some pointe 2023-05-01 07:27:08 Wow - I missed a great conversation. 2023-05-01 07:28:07 Looks like he uses subroutine threading. Another project that I'm interested in, CollapseOS, also claims to prefer this model: https://tumbleforth.substack.com/p/babys-first-steps 2023-05-01 07:28:11 xelxebar: I normally recommend "Forth Fundamentals, volume I," but if you've been carefully through jonesforth then you probably don't need it sas much - it's benefit is its "dive under the hood." 2023-05-01 07:29:11 unjust: That shell script must have been fun :D You have it up on a public repo somewhere? 2023-05-01 07:29:12 Subroutine threading is very popular - I think there's an almost automatic assumption that it must be the fastest. It usually is, but many years ago I found at least one counterexample. I can't remember what it is now, but it was back when you could just count machine cycles to tote up how long things would take to run. That processor just had slow subroutine calls. 2023-05-01 07:30:13 In most cases I think direct or indirect threading is more compact and subroutine threading is faster. 2023-05-01 07:30:42 I usually use indirect threading because a) it's more familiar to me and b) it just feels "more elegant" to me. 2023-05-01 07:31:03 Moving Forth claims that "On the 6809 or Zilog Super8, DTC is faster than STC." 2023-05-01 07:31:14 I've also had the impression that a couple of Forth features (primarily CREATE / DOES>) are more smooth to implement in indirect threading. 2023-05-01 07:31:47 It could be true - I can't remember. But I did a lot of 6809 work, so that tracks. It's one I would have done the counting on. 2023-05-01 07:32:17 Interesting that you go for ITC by default, I'd have assumed that DTC was mostly preferrable, since it avoids extra indirections. 2023-05-01 07:32:56 But ITC is more uniform, I guess :) 2023-05-01 07:33:06 Unless you put fairly large bits of code at the CFA positions, you wind up having to do that extra jump anyway. 2023-05-01 07:33:08 ITC is classic 2023-05-01 07:33:16 I.e., if you just put a jump at the CFA location. 2023-05-01 07:33:30 Yeah, it's just "traditional" and is the first thing I learned. 2023-05-01 07:33:41 It's a personal preference more than it is an optimization. 2023-05-01 07:34:18 My reasoning is usually that if I need absolute top speed I'll write key bits of code in assembly. 2023-05-01 07:34:21 After profiling. 2023-05-01 07:34:41 I think it may be easier to write a profiler for DTC and ITC, but that's kind of a guess. 2023-05-01 07:35:54 But code threading is super popular and htere's nothing wrong with it. 2023-05-01 07:37:22 BTW, what acronym does CFA stand for? 2023-05-01 07:37:25 xelxebar: i don't, i had hoped to write 80386, 80486, and later additions for it and some sort of basic ELF linker before releasing it. if you're interested in that, i'll create a repo with whatever state i had left it in. 2023-05-01 07:37:27 Even within ITC / DTC there are speed / size tradeoffs you can make. You can vary the size of those cells - even on, say, a 64-bit data stack Forth you can make the ITC/DTC cells 32 bits, or even 16 bits. That changes how the next code looks, and that changes the performance. 2023-05-01 07:38:00 So you can "turn that knob" in quite a few ways. 2023-05-01 07:38:34 CFA is code field address, iirc 2023-05-01 07:38:45 Argh. Gotta run. Family calls. Will jump back here in a few hours. 2023-05-01 07:38:47 Yes, that's right. 2023-05-01 07:38:53 Hey, good to meet you. 2023-05-01 07:39:18 The CFA field is the field that "always points to code." 2023-05-01 07:39:32 Well, or is code. 2023-05-01 07:39:42 Points to code in ITC. 2023-05-01 07:40:29 Actually if you try to turn that knob I mentioned to 16 bits, then you're probably writing a token-threaded system with 16-bit tokens. 2023-05-01 07:40:51 Because to make it work well you'll likely gather all your CFAs into a table. 2023-05-01 07:41:01 Then it looks a whole lot like token threading. 2023-05-01 08:33:05 Bank holiday in the UK today 2023-05-01 08:40:28 Oh yeah - that's right. That will affect my slate of meetings. 2023-05-01 08:47:43 And next week Monday too 2023-05-01 08:52:18 Fun. :-) 2023-05-01 08:53:55 Hey, you said something about a channel being a "good find" - was that referring to one of the links you posted, or did xelxebar post something too? I can't seem to find a link from him in the scrollback, but I may just be overlooking it. 2023-05-01 08:57:59 i think veltas was refering to Dave Smith's channel, check out https://forth.chat/logs/libera/forth/2023-05-01 to fill in the gaps 2023-05-01 08:59:01 Thanks. 2023-05-01 09:08:53 He made 'smithforth', his channel does seem quite good 2023-05-01 09:14:52 KipIngram: https://www.youtube.com/watch?v=9MSJGzYELBA 2023-05-01 09:15:02 Look also he made a spreadsheet program in forth 2023-05-01 09:15:08 Kind of interesting 2023-05-01 09:29:17 Oh, that is kind of an interesting idea. 2023-05-01 09:31:51 The spreadsheet has been an interesting thing over the years. I think it's evolved in interesting directions. Jupyter Notebook has some aspects of a spreadsheet in it - it's kind of a "free format" spreadsheet. 2023-05-01 09:32:12 A Jupyter notebook is kind of a "one column" spreadsheet. 2023-05-01 09:32:50 I still remember the look on the scientist's face when I told him Excel had been corrupting his data 2023-05-01 09:33:07 Ooops... 2023-05-01 09:33:08 some decades later, they renamed those genomes 2023-05-01 13:31:03 KipIngram: One of the things I'm interested in is how to solve the memoisation property of excel with forth nicely 2023-05-01 13:31:29 By "memoisation" I mean the spreadsheet remembers the results and doesn't recalculate unless it needs to 2023-05-01 13:31:38 how to make a hash of things 2023-05-01 13:31:53 Really that's not memoisation, it's more just lazy evaluation or something 2023-05-01 13:31:56 the most basic memoization/cache is a hash taable 2023-05-01 13:32:30 you use arguments as keys and results of the function as values 2023-05-01 13:33:12 needs to be a "pure" function 2023-05-01 13:33:42 which means does not matter how many times you call it with the same argument it will return the same result 2023-05-01 13:34:01 for example, no side effects, state, etc 2023-05-01 13:34:23 In a spreadsheet the cells can contain formulae, that can rely on each other, and are expected to get the result automatically 2023-05-01 13:34:57 The thing to memoise is just the cell contents, I don't think a hash is needed for that 2023-05-01 13:35:43 But you could probably do with a hash to track what's in the current dependency tree to detect loops 2023-05-01 13:36:33 no idea about excel so meh 2023-05-01 13:37:10 I should learn to use it xd 2023-05-01 13:37:42 Honestly worth learning excel basics, it's quite useful and it's used a LOT by non-programmers for essentially 'programming-lite' tasks 2023-05-01 13:38:20 yeah I'm trying to figure a use case 2023-05-01 13:38:30 mainly a secretary would use that a lot 2023-05-01 13:38:43 and to manage numbers 2023-05-01 13:38:46 "go here and click these options to turn off the "exec shits on your data" feature, and then watch it like a hawk to ensure "excel shits on your data" doesn't get turned on again" 2023-05-01 13:38:58 yeah... no 2023-05-01 13:39:32 veltas: any simple program that could use excel for something? 2023-05-01 13:40:03 I assume there's no a way to interface even in the open source versions 2023-05-01 13:40:49 oh js had an api 2023-05-01 13:40:50 An Excel add-in interacts with objects in Excel by using the Office JavaScript API 2023-05-01 13:40:51 xd 2023-05-01 13:41:03 https://learn.microsoft.com/en-us/office/dev/add-ins/reference/overview/excel-add-ins-reference-overview 2023-05-01 13:44:41 nah, I think I should learn it, but it's more for administrative purposes 2023-05-01 13:44:48 I don't have numbers to manage 2023-05-01 13:45:13 the thing is if the day comes, I'd be happy to know about 2023-05-01 13:45:24 I stopped using spreadsheets years ago and wrangle the numbers with other code 2023-05-01 13:46:26 except for those chuckleheads who sent an excel spreadsheet with five ip/port pairs hidden off on some tab so I had to waste a bunch of time finding something that could run open office, then finding where they had hidden the data, then wondering why they didn't just paste the ip/ports into the email and ditch the bloat 2023-05-01 13:46:34 the use I see on excel is to perform operation on several numbers 2023-05-01 13:46:46 it's kind of an alu + sql 2023-05-01 13:47:29 yeah for me is kind of a number database 2023-05-01 13:47:35 even if it's used also with text 2023-05-01 16:01:44 Forth n00b here. I if I set a shabang line at the top of my source file gforth gets upset. Is this expected behavior? 2023-05-01 16:03:56 http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Running-Image-Files.html#index-executable-image-file-3433 2023-05-01 16:10:12 thrig Thanks, apparently I needed a space between the shabang and the path. 2023-05-01 16:13:10 probably because there's a word for : #! ( -- ) \ gforth hash-bang 2023-05-01 16:27:11 vms14: The "obvious" use for a spreadsheet is to do calculations where the tabular layout of data is actually useful. But you can bend it in all kinds of clever ways - I've used it to numerically integrate differential equations and things like that. 2023-05-01 16:27:49 Each row would be a snapshot of the system's state at some instant, and you just calculate the "next state" from the rows above. 2023-05-01 16:29:04 jgaz: I thought Linux just used the shebang line to decide what file to ask to process the rest of the file - I would have assumed that the program selected wouldn't even see that first line. 2023-05-01 16:29:09 I figured Linux peeled it off. 2023-05-01 16:29:29 nope! whole file is sent as is 2023-05-01 16:29:38 That's what I thought too. 2023-05-01 16:29:54 Well, that seems silly, but I guess if it is that way it is. 2023-05-01 16:30:15 So then how can you set up a file so that you can just execute the file name and have gforth handle it? 2023-05-01 16:30:38 #! /path/to/gforth -i 2023-05-01 16:30:55 and then gforth has a word for #! that ignores that line 2023-05-01 16:31:06 I didn't even need the `-i` 2023-05-01 16:31:15 similar shenanigans happen in other languages, e.g. # is a comment in many things 2023-05-01 16:31:47 So basically you're telling gforth to treat the first line special? 2023-05-01 16:32:16 the first line just so happens to begin with a word that causes the line to be ignored