2023-01-25 01:59:59 Hi everyone, here's the rudiments of a Forth I am writing in around 300 lines: https://github.com/enthdegree/forth/blob/master/forth.c 2023-01-25 02:02:40 My requirements (I spammed them a few days ago) were that it had to be driven by the "next" function so that a parent can observe/control how many "primitives per second" it can run 2023-01-25 02:03:35 it's for a calculator, so double is the natural base data type 2023-01-25 02:04:51 other than error handling and pointer checking, does anyone have any deep criticism of this implementation so far? This is the first thing I've written resemblign a compiler 2023-01-25 02:05:45 so it likely has flaws. It seems to have a lot worse (complexity) to (functionality) ratio vs other compilers i've seen 2023-01-25 05:54:08 enthddd|||: This kind of behaviour is trivial to add to an existing forth, but there's no harm in writing your own Forth 2023-01-25 05:54:19 Probably half of the forth programmers write their own at some point 2023-01-25 06:25:38 enthddd|||: can you tell us more about the calculator part? 2023-01-25 06:27:09 also curious if double is the only data type and if so whether you plan to have ! and @ 2023-01-25 08:09:14 If double is the only data type then it would make sense to have double access and 32-bit signed access 2023-01-25 08:09:31 Because you can represent a 32-bit exactly in a double 2023-01-25 08:15:50 A lot of calculators use a bcd floating point representation, so they don't run into binary inability to represent "simple numbers" like 0.1 and so on exactly. 2023-01-25 08:16:23 Also, there are quad precision libraries around as well. 2023-01-25 09:05:48 KipIngram: Based on https://csclub.uwaterloo.ca/~pbarfuss/dekker1971.pdf I assume 2023-01-25 09:15:48 I don't know if it uses that or not. But you've got 34-digit precision calculators floating around, and a few nights ago I linked one of the common libraries that support that. 2023-01-25 09:16:45 It's not really a "trick" that uses lower-precision items in combination or something; it's a full up 16-byte per number representation. 2023-01-25 09:23:15 and floating point error can still ruin your calculations 2023-01-25 09:26:07 Yeah, if you stub your toe. Calculations are like dynamic processes, and sometimes a calculation can be chaotic, such that small perturbations can grow exponentially. 2023-01-25 09:26:34 KipIngram: linking the BCD lib is on my list. how hard is that to do? 2023-01-25 09:26:37 like floating point didn't get the memo that the magnitude of the velocity of a circular orbit needs to be constant 2023-01-25 09:26:39 And there are also just situations that are naturally bad, like when you subtract nearly equal quantities - that chews up a lot of your precision. 2023-01-25 09:26:50 Oh, I haven't actually done it. 2023-01-25 09:27:01 I just ran across a web page for such a library, and shared it. 2023-01-25 09:27:06 ah ok 2023-01-25 09:27:29 I tried a long time ago but it seemed somehow precompiled for x86 and I couldnt figure out how to get it to work for other architectures 2023-01-25 09:27:42 Yeah, sometimes such things are a nuisance. 2023-01-25 09:30:10 enthddd|||: Primary support for whatever float format you want to use is nice, but hopefully you'll also be able to work with integers, because you need that for basic "system" programming. 2023-01-25 09:30:35 Just to do things like put an address on the stack. 2023-01-25 09:37:55 I'm quite interested in eventually being able to do smooth scientific calculations, but I decided at some point that that support should be added after the fact, not wired into the basic system itself at the ground floor. 2023-01-25 09:38:44 I figure I'll eventually write an interpreter that maintains a stack of pointers to typed items, and those will be able to be more or less anything. Ints, floats, complex, vectors, arrays, strings, etc. 2023-01-25 09:38:46 Lists. 2023-01-25 09:38:50 The whole nine yards. 2023-01-25 09:39:18 And it'll have some kind of dynamic memory management behind it, that's transparent to me at the operational level. 2023-01-25 09:39:44 (mostly transparent, Common LISP is good at hiding the memory until it isn't) 2023-01-25 09:39:53 When I search for a word, the pattern of types at the top of the stack will guide the search - I'll only find words that accept a matching pattern of types. 2023-01-25 09:40:09 Yeah, mostly transparent. Good way of putting it. 2023-01-25 09:40:45 (in the lisp machine days the GC was buggy so they turned it off and rebooted the system every few days) 2023-01-25 09:41:15 Here and there you still find such buggy things. 2023-01-25 09:41:36 I installed Android Studio a few days ago and had it open over in a workspace while I was doing other things. 2023-01-25 09:42:04 A couple of days later my system just froze and I had to power cycle. I don't KNOW it was that application, but I suspect it was. 2023-01-25 09:42:52 You'd THINK that at the very least they could have a system like this to the point where it was impossible for a user space application to hose down the whole system, but apparently we're not there yet. 2023-01-25 09:43:23 Supposedly user programs are boxed in with security barriers. 2023-01-25 09:44:32 welllllll it might take up too much graphics resources which are done in X or elsewhere, or maybe there's kernel allocations and whoops or 2023-01-25 09:45:19 I know. I think all this has just gotten so complicated that no one can keep up with it well enough to be sure of stability. 2023-01-25 09:45:53 I think that's where things like Spectre/Meltdown come from too. Neither party there really fouled up their own job - they just didn't pay enough attention to what one another was doing. 2023-01-25 09:46:22 Just an unforseen interaction that someone figured out how to exploit. 2023-01-25 09:46:35 and then you want it to be fast, but then you might want it slow enough so that when it goes crazy you can still have free cycles to kill it but probably you'll be hitting the reset button 2023-01-25 09:47:25 if you can get process creation (and high memory use) out ahead of the OOM killer, linux will shit itself 2023-01-25 09:49:23 Yeah, I know. But supposedly the memory protection hardware keeeps a process out of system RAM, and you'd think that as long as one core was still in the system's hands it could clean everything up. 2023-01-25 09:49:45 It *seems*. But obviously I don't know how involved it all is. I really do think we've just let the complexity beat us. 2023-01-25 09:50:36 And yes, I do think it's the pursuit of ultimate performance that gets us there. Probably are strongly safe ways of doing things, but they'd be slower. 2023-01-25 09:51:44 Like in the spectre/meltdown case, they let privileged instructions go ahead and "pre-execute," and relied on the security to unwind them. So the cache effects survived. The *right* thing to do would be to check the instruction privilege BEFORE pre-executing it, but I assume that would have impacted performance. 2023-01-25 09:51:51 Or added logic or something. 2023-01-25 09:52:01 a group using 63 cores will fall behind a group using 64 cores, and anyways the system doesn't go nuts too often 2023-01-25 09:52:12 They clearly figured as long as the instruction got cancelled later it was good enough, but it wasn't. 2023-01-25 09:52:34 No, that's true. I have good respect for Linux. 2023-01-25 09:52:43 It's amazing to have such a tool so readily avaialble. 2023-01-25 09:53:10 And it mystifies me that the world displays such a strong preference for a commercial product instead. 2023-01-25 09:53:53 A *crap* commercial product at that. 2023-01-25 09:55:16 I do wish Linux gave more overt control of system resources, though. I'd like to be able to easily say "I want this run on core x, and I want ALL of core x's attention." And that would cause the system to totally unload it's own business from core x. 2023-01-25 09:55:35 The opacity of that layer is kind of frustrating. 2023-01-25 09:55:36 pretty sure you can pin processes 2023-01-25 09:56:14 You can, and even tie interrupts to certain cores. 2023-01-25 09:57:21 See taskset and friends to set process affinity. 2023-01-25 09:58:21 Yes, I've recently used taskset in work work. 2023-01-25 09:58:26 And nice as well. 2023-01-25 09:58:44 But I don't think any of that guarantees TOTAL core control. 2023-01-25 09:58:54 The system still might use it, right? 2023-01-25 09:59:31 I don't recall offhand, but I know it's possible. It was added for all of that NUMA stuff. 2023-01-25 10:13:45 KipIngram: couldnt you get away with doubles only? even for memory access it should work. Java does something like this im told 2023-01-25 10:14:19 You must mean double integers. 2023-01-25 10:14:22 Yes, you could do that. 2023-01-25 10:14:28 I was thinking of floating point double precision. 2023-01-25 10:14:37 I do mean floating point double precision 2023-01-25 10:14:52 How would you load a variable to the stack? 2023-01-25 10:14:53 you can access memory with them if they can hold all integer memory addresses you need to refer to 2023-01-25 10:15:08 Wouldn't the set higher bits interfere? 2023-01-25 10:15:34 It's not something I've actually thought about. 2023-01-25 10:15:50 not if you convert the double to an integer for ! and @ but leave it a double otherwise 2023-01-25 10:16:08 convert internally I mean within the primitive when the double is consumed 2023-01-25 10:16:39 Well, sure, you could explicitly convert. 2023-01-25 10:16:42 Fair enough. 2023-01-25 10:17:10 What would be even nice would be to have the pattern with the exponent and sign bit all clear represent a valid integer. 2023-01-25 10:17:24 Then as long as you limited your range it would "just work." 2023-01-25 10:22:42 Maybe that does work - I don't know. 2023-01-25 10:23:17 It would have been a smart way to do it. 2023-01-25 10:28:24 ya it would be cool if you built that into your floating point representation 2023-01-25 10:31:18 It would. If I ever do one I'll keep that in mind. 2023-01-25 10:32:26 It doesn't work in gforth, though: 2023-01-25 10:32:28 variable alpha ok 2023-01-25 10:32:30 1 s>f alpha f! ok 2023-01-25 10:32:32 alpha @ . 4607182418800017408 ok 2023-01-25 10:32:50 Well, gotta run to work. 2023-01-25 10:32:54 Later, guys. 2023-01-25 10:32:57 Stay safe. 2023-01-25 10:33:22 with my orbital calculations? probably not 2023-01-25 16:10:54 It occurred to me to do the above test the other way: 2023-01-25 16:10:56 variable alpha ok 2023-01-25 16:10:58 1 alpha ! ok 2023-01-25 16:11:00 alpha f@ f. 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000494065645841247 ok 2023-01-25 16:11:09 That is... a very small number. 2023-01-25 16:11:14 Of course, it has to be, though. 2023-01-25 16:11:27 Because exponents in floating point are centered around zero. 2023-01-25 16:11:43 So if you take an 8-bit exponent field, it will represent exponents from -128 to 127. 2023-01-25 16:11:44 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is a very small number 2023-01-25 16:12:02 So the exponent you'd need for "1" is there in the middle of its range somewhere. 2023-01-25 16:12:22 https://www.youtube.com/watch?v=3gyHKCDq1YA 2023-01-25 16:12:32 MrMobius: To achieve what we discussed earlier, you'd need for exponent 0 to be 2^0. 2023-01-25 16:13:00 So you'd need to treat the exponent field as a signed integer, instead of an "offset shifted" integer. 2023-01-25 16:13:18 I'd have to ponder on it more to come up with reasons (possible reasons) w hy they didn't do that. 2023-01-25 16:14:07 But that is all you'd need to do, to make it work. 2023-01-25 16:14:26 Put the sign bit at the MSB, then the exponent bits, and treat the exponent as a signed integer. 2023-01-25 16:14:39 Then all zeros in the high bit would mean positive and *2^0. 2023-01-25 16:14:53 And integers would carry the right floating point value. 2023-01-25 16:14:59 That's VERY appealing, actually. 2023-01-25 16:21:03 Ah - if I'm not mistaken (only thought about it for a minute) doing it the way they do it makes the numerical ORDER of floating point numbers correct. 2023-01-25 16:21:26 In other words, if you compare to floats by comparing them as unsigned integers, you'll get the right conclusion. 2023-01-25 16:21:42 Whether that's more or less valuable than the other feature, I don't know. 2023-01-25 16:35:35 I'm not sure I think comparison beats "actual usage" in terms of value. For Forth, particularly, it would be awfully nice to be able to put an item on the stack be able to add it with an operation without having to worry about whether it was an int or a float. 2023-01-25 16:35:56 Though, I guess that would have to be the floating point add, of course - the slow one. 2023-01-25 16:36:06 And it would only work for positive integers. 2023-01-25 16:36:18 So maybe I'm giving it too much credit right now. 2023-01-25 16:41:45 It is the case that floating point zero and zero are the same bit string. 2023-01-25 16:41:54 and integer zero, I mean. 2023-01-25 16:51:08 I still am inclined to add the whole suite of HP calculator stack instructions as words in my next Forth. Those are useful. 2023-01-25 16:51:41 Well, they're useful at least when you're doing floating point calculations. I guess all that old experience was oriented in that direction. 2023-01-25 17:31:19 In this "event loop" driven approach, I suppose the idea would be for the "console session" to be a software object that knows how to respond to events of various types. It would handle a keystroke event by inserting the key into its buffer. So that buffer will internally know several of those things that were cluttering up the stack in my EXPECT. 2023-01-25 17:31:59 There may still be a word EXPECT, but it will operate by taking its parameters and "posting" them as the current keystroke receiving buffer and so on. 2023-01-25 17:32:39 And when it receives an Enter keystroke, that will finish up its work and it will move on. 2023-01-25 17:33:33 So the ultimate effect of the change *will* be that there are variables somewhere that hold those things. In this case, though, they seem a lot less arbitrary than they would if I just stuck them into EXPECT for purposes of clearing the stack. There's a sort of "sense" to them. 2023-01-25 17:36:18 The events I can think of that a "console session" entity would know how to respond to would be keystrokes, mouse clicks, and perhaps waiting for disk operations to finish. Those seem like the ones that would come built-in, though you might also want some sort of "signal handling." 2023-01-25 18:22:24 really interesting thoughts, thinking about them 2023-01-25 18:25:01 i believe equivalent functionality to @ and ! can be implemented as a dictionary lookup + drop word + redefine word 2023-01-25 18:26:42 i would like to be able to use an off-the-shelf forth, but the target application is very constrained (sensorwatch.net ; 256 kb flash, 32 kb ram, you talk to forth using morse code) 2023-01-25 18:27:20 for calculator functions i am just using math.h 2023-01-25 18:28:29 bcd and management of error accumulation (or maybe arbitrary precision) would be really cool but would probably be over-engineering at this point 2023-01-25 18:28:44 That's a lot of flash and ram for Forth. 2023-01-25 18:29:00 A Forth would have no problem fitting in that. 2023-01-25 18:30:54 Here's the python package that provides arbitrary precision math: 2023-01-25 18:30:55 https://mpmath.org/ 2023-01-25 18:31:03 You could probably find out what library they use. 2023-01-25 18:31:17 I played with it some a week or so ago; it's easy to use. 2023-01-25 18:31:28 In Python, I mean - I didn't play with interfacing the library. 2023-01-25 18:31:44 the character set is also [a-z0-9] +=-_/?!"'.,:;@() 2023-01-25 18:32:00 cool i didnt know about this 2023-01-25 18:32:10 Ah, one of those Chuck style character sets. :-) 2023-01-25 18:33:23 I've never taken that plunge. I've just stuck with ASCII, though fairly recently I upped to utf8 support. 2023-01-25 18:33:52 KEY will return all bytes of a utf8 character in the cell it returns, and EMIT will print a multi-byte char as well. 2023-01-25 18:34:05 EMIT does no checking, though - it just spews hte bytes out and trusts they're ok. 2023-01-25 18:49:56 Wow. mpmath looks like a thorouhly complete package. 2023-01-25 18:50:09 Has more or less everything you could ask for math-wise. 2023-01-25 19:39:41 I've watched the first couple of episodes of Amazon's Tolkien series, Rings of Power. 2023-01-25 19:40:52 It's ok so far. But it's odd - they're setting up a prominent hobbit character, but this series is set much earlier than Lord of the Rings, and a point strongly made in LotR was that before Bilbo and Frodo's adventures, hobbits had never played any particularly important role in things. 2023-01-25 19:41:05 So that doesn't quite "fit." 2023-01-25 19:41:07 https://acoup.blog/2022/12/16/collections-why-rings-of-powers-middle-earth-feels-flat/ 2023-01-25 19:41:26 I'm not far enough in to say yet. 2023-01-25 19:41:35 Galadriel is easy on the eyes, at least. 2023-01-25 19:42:04 It's got all of the "markers" of a politically correct series, loud and clear. 2023-01-25 19:51:20 Anyway, the Galadriel character seems so far like a good "younger precursor" of her character in LotR. 2023-01-25 19:52:41 Re: the PC stuff, if someone has an earnest desire to tell a story that way, I'm fine with that. What I worry about, though, is that we'll eventually find ourselves in a world where content that *doesn't* go the overt extra mile on that front will get rejected. And I think that would be an undesirable world. 2023-01-25 19:53:03 I worry we'll wind up with a set of "checkboxes" that have to be ticked off in order to be let in the door. 2023-01-25 19:53:22 so uh no "Blazing Saddles" ? 2023-01-25 19:55:29 Oh my God - that would NEVER fly these days. Thank GOD we got it when it could slip through. 2023-01-25 19:55:38 Because that's FUNNY. 2023-01-25 19:56:21 I've often thought Queen's "Fat Bottomed Girls" would have a hard time these days too. 2023-01-25 19:56:44 There's just something to be said for audacity. 2023-01-25 20:32:04 By the way, do you think ASCII has too many control codes, and say, 8 would be more than enough? 2023-01-25 20:32:17 https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0 2023-01-25 20:33:16 it would have been nice if some of the codes had been used, instead of say CSV files 2023-01-25 20:42:38 thrig, which shows why having dedicated separator characters is not very useful, since they always can be found inside the fields. For example if US/RS/GS/FS were used then if you wanted to insert a fragment of other database in a cell you'd get a mess 2023-01-25 20:43:11 so introducing them was a waste of codepoints anyway 2023-01-25 20:44:19 And you can use \t as field and \n as record separators instead 2023-01-25 20:44:31 And two more levels are probably useless 2023-01-25 20:45:49 Though if I were inventing ASCII, I'd add a paragraph separator \p and page separator \f for example 2023-01-25 20:46:12 Then they work as two more separators and make US/RS/GS/FS irrelevant completely 2023-01-25 20:47:46 If you'd like to embed a line break or something inside a field then you can use \e to escape it 2023-01-25 20:50:29 So it would be \s \t \n \p \f \e Xon Xoff control codes for example, where \s means ' ' and \p means paragraph break, which would be rather useful as semantic marker rather than linebreak which might be used as reflow marker 2023-01-25 20:50:58 and xon/xoff are necessary for software flow control to make the sender pause/resume transmission 2023-01-25 20:52:36 Since both space and \0 have no printable glyph it would make sense to use binary 0x00 as code for whitespace 2023-01-25 20:54:17 So what's your opinion, would ASCII survive with just 8 control codes (or even 7, if you count whitespace as a printable) instead of 34 (33 w/o space)? 2023-01-25 20:54:37 that's a different history that also has various flaws 2023-01-25 20:55:10 But 26 more printable characters 2023-01-25 20:58:00 thrig, also what 26 printable characters would be most useful as universally available ones? 2023-01-25 20:58:23 Maybe combining characters for diacritics? 2023-01-25 21:00:35 Such as é, è, ö, ñ, ç, ĉ, č, ø 2023-01-25 21:17:48 thrig, what printable characters you find most essential and which should have been in ASCII? 2023-01-25 21:18:16 I think some character for XOR would be good, since ^ is used for both XOR and power which is not good 2023-01-25 21:19:48 it's missing a couple of math symbols 2023-01-25 21:20:38 times × and divide ÷ 2023-01-25 21:20:51 If you are talking about \/ /\ for AND and OR, then I think & and | are better 2023-01-25 21:20:56 dave0, but * and / 2023-01-25 21:21:20 Stalevar: yeah but * and / are just what we use as substitutes 2023-01-25 21:21:40 / is used as division on paper too 2023-01-25 21:21:41 an euro sign as well as a dollar sign would be helpful 2023-01-25 21:22:02 € didn't exist when ASCII was invented 2023-01-25 21:22:14 Maybe ¤ as universal currency? 2023-01-25 21:22:15 oh i didn't realize that! 2023-01-25 21:22:24 good point 2023-01-25 21:23:12 Some codepages have ¤ in place of $ 2023-01-25 21:23:32 For example KOI7 which was used in Radio 86rk 2023-01-25 21:23:49 more stuff might screw up the careful placements for sorting to work 2023-01-25 21:24:20 it would have been interesting if the letters were laid out as aAbBcCdDeEfFgG .. 2023-01-25 21:24:33 intereting for sorting 2023-01-25 21:25:00 I think existing order of letters when changing just one bit changes the case is probably fine 2023-01-25 21:25:24 !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ 2023-01-25 21:25:38 But ASCII can probably have included more characters 2023-01-25 21:25:40 pretty sure @ is at 100 because The French 2023-01-25 21:26:26 but it's 0x40 2023-01-25 21:26:54 what is @ used except email separator anyway? 2023-01-25 21:27:13 the most important character in rogue 2023-01-25 21:27:41 That's only because it was available on the computer rogue was written on 2023-01-25 21:27:52 was it not it would have been a different character 2023-01-25 21:28:45 @ is fetch! 2023-01-25 21:29:42 That's the same, it got used in this role only because it was available on the system where forth was written on. Though $ is more often used as fetch 2023-01-25 21:29:50 $HOME for example 2023-01-25 21:30:00 or $_ in Perl 2023-01-25 21:30:32 Stalevar: I'd never given ASCII control code much thought. My biggest heartburn with ASCII is that it makes dual use of the escape character. 2023-01-25 21:30:44 On the one hand, it's a character - it's even a key on the keyboard. 2023-01-25 21:30:52 On the other it's the prefix for control sequences. 2023-01-25 21:31:10 But it makes sense, perhaps you want to type control sequences yourself 2023-01-25 21:31:11 So when you receive it, you don't know which you're dealing with, without doing backflips with timing and so on. 2023-01-25 21:31:23 Yes, but it should be a dedicated key with no other use. 2023-01-25 21:31:42 That's the only problem. 2023-01-25 21:32:06 utf8 is more well thought out - you know from the first byte you're getting a utf8 sequence. 2023-01-25 21:32:12 you could invent a better terminal but then the problem is getting people to use it and getting usable software on it 2023-01-25 21:32:33 Ctrl+[ 2023-01-25 21:32:36 Well, and I've always figured that they didn't necessarily know what the future was going to be when they first set out. 2023-01-25 21:32:39 Yes. 2023-01-25 21:33:04 But at any rate, I don't know offhand what all the control characters are for. 2023-01-25 21:33:14 I suppose they all made some sense in the context of old input machines. 2023-01-25 21:33:25 https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0 2023-01-25 21:33:44 Still catching up on the earlier conversation. 2023-01-25 21:33:53 \r and \n made sense for dumb teletypes which didn't have any smart electronic circuitry 2023-01-25 21:34:20 so single \n code wasn't enough for both carriage return and line feed 2023-01-25 21:35:38 I like & and | for logic too. 2023-01-25 21:35:59 :-) Euro symbole - man that would have been prescient of them. 2023-01-25 21:36:13 I remember when the Euro came about. 2023-01-25 21:37:25 Oh, that's an interesting point about $ being fetch. I'd never thought of WHY that symbol is required to get at environment variables. 2023-01-25 21:38:42 In Tcl everything is a string, so say variable names work as pointers to variables, but if preceded by $ it means that certain string is to be replaced with value of variable, same goes to shells 2023-01-25 21:38:55 if you define a variable you don't need $ though 2023-01-25 21:38:58 set a 5 2023-01-25 21:39:01 puts $a 2023-01-25 21:39:32 because `set` knows that first parameter is a variable name 2023-01-25 21:39:36 Though you can do this 2023-01-25 21:39:40 set b a 2023-01-25 21:39:50 set $b c 2023-01-25 21:40:20 puts $a ;# prints "c" 2023-01-25 21:40:40 KipIngram, does it make sense? 2023-01-25 21:42:01 Also `set` with one parameter works as fetch, so puts $a is equivalent of puts [set a] 2023-01-25 21:55:19 KipIngram, also an environment variable and a shell variable are different things. Did you know that?