2024-03-29 00:44:43 Could we use stack notation in source code as assertions? 2024-03-29 00:45:27 no 2024-03-29 00:45:31 : thing ( a b -- n ) dup dup + ( a b n ) + ( n ) ; 2024-03-29 00:45:37 i won't allow it, sorry 2024-03-29 00:45:44 I mean develop a forth with that 2024-03-29 00:45:49 Or is there a problem Im not seeing 2024-03-29 00:45:55 also check out factor, it does this 2024-03-29 00:46:20 well, not the intermediate ones 2024-03-29 00:47:12 but the ones at the beginning of a word definition, it requires those and uses them for compile time checking 2024-03-29 00:48:15 nice. 2024-03-29 02:31:19 thinking of how i might design a file output collection of words 2024-03-29 02:32:25 not looking for full blown file i/o support, i just need a few words to specify "this memory range should be written to disk with this filename when i'm done" 2024-03-29 02:35:28 what do you think about some bastardized block type of word set? maybe "filename size buffer" allots size, opens filename for writing, and then later you say "save" to write all open buffers and ckose their files 2024-03-29 02:36:38 but i need a ckean nice way to tell it how much of the buffer is actually used 2024-03-29 02:39:55 as i was typing i just had another idea. "size buffer foo" creates a new buffer called foo with size allotted. then you bind it to a filename later with something like "filename foo open" and then foo contains a pointer field that you can update as you populate, and finally "foo save" to write, close, and reset 2024-03-29 02:41:49 this is just for the host environment that implements a target compiler, so it can and should be kept simple to implement and use. doesn't need to ne general purpose. 2024-03-29 16:14:03 Does anyone know of a forth for the attiny85? 2024-03-29 16:39:12 IVT: https://github.com/zooxo/ivt 2024-03-29 16:39:47 very limited though 2024-03-29 16:42:00 https://github.com/l3chat/tn85eForth is an eforth 2024-03-29 16:43:16 those are all I see in my notes 2024-03-29 16:43:18 Ah nice 2024-03-29 16:43:22 Thank you :) 2024-03-29 16:44:33 sha256.f - not completely working but basically done https://gist.github.com/lf94/61fce9337a624c52f161a062042c0ae4 2024-03-29 16:44:49 387 lines of forth for a completely system agnostic sha256 2024-03-29 16:50:41 I'm not generally a fan of the vertical style, but this looks clean and the stack comments make it easy to follow. 2024-03-29 16:54:26 I'm really starting to see stack comments as assertions 2024-03-29 16:54:59 In more powerful forth interpreters there should be an option, "all lines must be asserted" :p 2024-03-29 16:55:29 Would make it harder to mess up the easiest mistake in forth 2024-03-29 16:56:04 you could also test your words 2024-03-29 17:00:18 Most of my words don't have deep enough stack use to get confusing 2024-03-29 17:03:07 And I have facilities for dealing with some things that often need a bunch of stack shuffling 2024-03-29 17:03:40 e.g., I'd implement your 32dup as :32dup 'abcd 'abcdabcd reorder ; in my systems 2024-03-29 17:08:00 Not really related but this just popped into my head http://programming.sirrida.de/calcperm.php 2024-03-29 17:08:08 "Code generator for bit permutations" 2024-03-29 17:11:05 GeDaMo: this looks interesting; I've bookmarked it for further review; thanks! 2024-03-29 17:14:11 :) 2024-03-29 17:15:34 zelgomer: I'd like something a bit more passive like the assertions but good point! 2024-03-29 17:15:47 crc: :o what's that? what's the quote notation? 2024-03-29 17:16:21 'abcd is a string with the characters abcd 2024-03-29 17:16:37 (this is from my forths, retroforth & konilo) 2024-03-29 17:25:04 That seems quite useful. I have a way of avoiding stack noodling too, but quite different from that. How about bits? Do you have any bit shuffling words? 2024-03-29 17:25:52 I once thought about a word that would let you stick four 64-bit items on the stack (so, 256 bits), and then specify an arbitrary permutation action on them as a single 256-bit item. 2024-03-29 17:26:05 The kind of stuff that would be likely to come up in cryptography. 2024-03-29 17:26:54 "Thought about" being operative there - like so many such things it never got implemented. 2024-03-29 17:26:59 KipIngram: that link I posted may be of interest for bit permutations 2024-03-29 17:28:12 I've been watching a good bit of cryptography stuff on Computerphile lately. It's a little sad how vulnerable so much of what we actually use is, one way or antoher. 2024-03-29 17:28:15 another 2024-03-29 17:28:42 The one that really took the cake for me is that we let NIST just give us "magic numbers" for one of those schemes. "Trust us - they're good numbers." 2024-03-29 17:28:57 Surprise surprise - turns out one of them isn't. 2024-03-29 17:29:05 What did people expect? 2024-03-29 17:29:21 And then NIST said that your product couldn't be FIPS certified unless it used those numbers. 2024-03-29 17:30:03 When I heard that whole story it just immediately turned FIPS into something to AVOID as far as I'm concerned. 2024-03-29 17:35:12 KipIngram: not many. I have the normal shift-left and shift-right, and, or, xor, not; as well as bit:set, bit:get and bit:clear. 2024-03-29 17:35:58 my son had mentioned that he was working on addtional words involving bit manipulations, but I've not seen what he's been doing on this yet 2024-03-29 17:47:05 Or you're the retroforth author? Damn, nice to meet you! :) 2024-03-29 17:55:08 Yes, thanks :) 2024-03-29 17:56:56 Or -> Oh 2024-03-29 18:00:23 Is there a forth with better error reporting 2024-03-29 18:00:25 gforth really sucks 2024-03-29 18:04:38 maybe 4th from Hans Bezemer 2024-03-29 18:04:49 https://thebeez.home.xs4all.nl/4tH/ 2024-03-29 18:10:24 Thank you 2024-03-29 18:12:55 How do I print a value in hex notation 2024-03-29 18:13:04 When using .S, etc 2024-03-29 18:13:33 hex .s 2024-03-29 18:13:37 in most systems, use hex .s 2024-03-29 18:13:43 decimal to go back to base ten 2024-03-29 18:14:28 There was somebody in another channel a while back who was trying to go back to decimal with 10 base ! and couldn't understand why it wasn't working :P 2024-03-29 18:18:07 lol 2024-03-29 18:18:37 10 exists in many bases 2024-03-29 18:18:45 After I verify this function matches actual sha256 values, I'd _love_ if you guys could make suggestions on how to make it easier to understand. 2024-03-29 18:19:10 I really want to conquer the "weakness" of forth, which is stack manipulation 2024-03-29 18:21:09 I really think the assertion idea could remove a massive host of forth-related errors 2024-03-29 18:22:53 I seem to remember a system whereby you could specify stack shuffling with something like ( 1 2 3 -- 3 3 1 1 )and it would generate the necessary code 2024-03-29 18:23:49 http://www.sovietov.com/app/forthwiz.html 2024-03-29 18:24:27 also https://github.com/mschuldt/forth_wizard 2024-03-29 18:27:40 cool 2024-03-29 18:29:58 How do I force gforth to print everything in the stack 2024-03-29 18:30:04 And not like, the top 10 elements 2024-03-29 18:30:50 hash functions like sha256 are really great for testing a language 2024-03-29 18:37:01 try setting maxdepth-.s 2024-03-29 18:37:14 100 maxdepth-.s ! 2024-03-29 18:40:54 hm 2024-03-29 18:40:56 h0 32@ h1 32@ h2 32@ h3 32@ h4 32@ h5 32@ h6 32@ h7 32@ 2024-03-29 18:40:58 100 maxdepth-.s 2024-03-29 18:41:00 hex .S 2024-03-29 18:41:02 nope 2024-03-29 18:41:17 you need the ! after the maxdepth-.s 2024-03-29 18:42:25 Oh it's an internal address 2024-03-29 18:42:40 I thought it was a word w/ some sort of side effect to the interpreter - cool :o 2024-03-29 18:43:27 Perfect :) 2024-03-29 18:43:39 <20> 1 67 F6 46 52 C5 BE 64 1C C7 A2 A5 42 ED 64 F0 96 D6 C6 8B E0 CD DC 98 D2 A9 52 55 33 1 38 8F 2024-03-29 18:43:53 32 bytes, aka 256 bits 2024-03-29 18:44:00 Cool the stack counter changed to hex too lol 2024-03-29 18:44:45 doesn't match echo -n "hello world" | sha256sum yet though ;) 2024-03-29 18:44:54 $ echo -n "hello world" | sha256sum 2024-03-29 18:44:56 b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 - 2024-03-29 18:45:12 I wonder where I go wrong 2024-03-29 18:48:55 how about an empty string? 2024-03-29 18:49:33 or a shorter string? 2024-03-29 18:51:35 or a slower string? 2024-03-29 19:12:03 Ill try the empty 2024-03-29 19:12:42 Is s" " an empty string in forth? 2024-03-29 19:12:55 <20> AF CD CB BE 1 2B 93 DC DD 2 70 EF B8 CB 23 77 8A 74 CA 1A D4 6B E0 27 62 85 D9 6F C0 EB A3 5C 2024-03-29 19:13:04 $ echo -n "" | sha256sum 2024-03-29 19:13:06 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - 2024-03-29 19:19:03 are you sure the bytes in the kXX and hX lines are in the correct order? 2024-03-29 19:50:18 I'm not, I'm also thinking my 512 bit window is wrong too 2024-03-29 19:50:23 Working on it now 2024-03-29 19:50:33 What's a nice little word for making an assertion you think? :) 2024-03-29 19:50:44 : test a b != if bye then ; ? 2024-03-29 19:50:59 Probably want to print the stack at that point 2024-03-29 19:51:13 : test a b != if .S bye then ; 2024-03-29 20:08:36 : assert ( a b) != abort" game over" -; 2024-03-29 20:08:45 oops, ; not -; 2024-03-29 20:13:29 what's the difference between bye, abort, exit? 2024-03-29 20:14:29 bye terminates the program with exit code 0, abort terminates with exit code 1 (i guess), and exit returns to the calling word 2024-03-29 20:14:36 exit is a control flow word 2024-03-29 20:14:42 it's like "return" in most other languages 2024-03-29 20:15:33 oh nice ok 2024-03-29 20:15:38 abort "empties the data stack and does a QUIT" etc (if you follow ANS and stuff) 2024-03-29 20:15:47 : assert ( bool ) if abort then ; 2024-03-29 20:15:48 oh, that's right 2024-03-29 20:15:58 3 6 != assert 2024-03-29 20:16:00 reads nicer 2024-03-29 20:16:22 need to dup them tho 2024-03-29 20:16:24 hm 2024-03-29 20:16:36 lf94: there is a word called abort" that takes a string and has the if built-in 2024-03-29 20:17:04 im big on avoiding these words that combine things _for now_, as I learn 2024-03-29 20:17:47 learnin' them basic moves is important 2024-03-29 20:18:06 : assert ( a b ) dup dup != if .S bye then ; 2024-03-29 20:18:15 this is best I think 2024-03-29 20:18:17 3 6 assert 2024-03-29 20:18:22 assert_eq ? 2024-03-29 20:18:33 assert= 2024-03-29 20:18:35 :) 2024-03-29 20:19:19 that's fine, but there is also wisdom to be gleaned from seeing how others have designed higher level interfaces 2024-03-29 20:20:05 assert=== 2024-03-29 20:20:14 oh wait no don't copy JavaScript 2024-03-29 20:21:13 assert==== then 2024-03-29 20:21:31 assert<>not 2024-03-29 20:22:07 granted Common LISP has like eq eql equal equalp and others 2024-03-29 20:26:48 wtf is not in forth 2024-03-29 20:26:50 <> ? 2024-03-29 20:27:03 assert<> 2024-03-29 20:27:04 <> is "not equal" 2024-03-29 20:27:06 perfect 2024-03-29 20:27:07 "not" is "not" 2024-03-29 20:27:11 yea yea my bad 2024-03-29 20:27:16 you knew what I meant :) 2024-03-29 20:34:12 oddly enough gforth is not aborting 2024-03-29 20:35:04 : assert= ( a b ) dup dup <> if .S bye then drop drop ; 2024-03-29 20:35:23 35 530 assert= 2024-03-29 20:35:34 I tried abort too 2024-03-29 20:35:39 "dup dup" is just going to dup 530 twice 2024-03-29 20:36:06 and <> consumes both items regardless of the result, so you probably didn't want "drop drop" there either 2024-03-29 20:42:08 derp 2024-03-29 20:42:11 Im an idiot 2024-03-29 20:42:14 I wanted over over 2024-03-29 20:43:00 I wish forth had a 1st, 2nd, 3rd, etc word, but I quickly realize these would not be "operations"... 2024-03-29 20:43:19 There's also 2dup 2024-03-29 20:43:19 (aka I quickly realize the error of my thinking :p) 2024-03-29 20:43:23 programming: 5% ima genius 95% ima idiot 2024-03-29 20:43:29 yes 2024-03-29 20:43:55 I wonder if "stack assertion" wouldve helped here. 2024-03-29 20:50:01 lmfao my sha function is some how indeterministic 2024-03-29 20:51:24 long way to say buggy 2024-03-29 20:56:01 I think I need to rewrite new_message_512_aligned 2024-03-29 21:15:13 This assert= is super ultra useful. 2024-03-29 21:23:20 The Rebol language has a 'probe' function which prints out the value but also returns it 2024-03-29 21:23:37 So you can put it pretty much anywhere to find out what a value is 2024-03-29 21:27:25 The assert= is nice because it stops me from continuing development, AND it forces me to make small Forth words 2024-03-29 22:09:35 GeDaMo: One "personal convention" I wound up adding to my system was to let a . prefix on a word mean "same as the usual word, but keep one otherwise discarded stack parameter." So .= would do the same thing as =, and would still discard the top stack aprameter, but would keep the bottom stack parameter. Good for doing a whole series of comparisons. 2024-03-29 22:10:25 Anyway, I added that for my conditional return words, but later on I added the word .. which "does what . does, but keeps a (or "the" in this case) parameter. 2024-03-29 22:10:36 So I can just drop in .. wherever I want a peek at what's on the stack. 2024-03-29 22:11:26 The main way I debug is by moving debug prints around. "Binary" search may way in on trouble spots. 2024-03-29 22:12:37 yeah don't really use debuggers here. prints and assertions and minimum test code bits elsewhere 2024-03-29 22:40:52 I dont think I use a debugger ever 2024-03-29 23:13:38 important question. "-" versus "--" in stack affect comments. ok go. 2024-03-29 23:17:11 I voted for Kodos 2024-03-29 23:17:54 I think -- is better because you may want to use - to signify a negative parameter 2024-03-29 23:18:11 Ive been using : as a type separator 2024-03-29 23:18:19 ( a:bits - b:bits) 2024-03-29 23:45:53 I think my 32+ is indeterministic 2024-03-29 23:45:57 it's random though 2024-03-29 23:46:00 super weird 2024-03-29 23:52:11 damn this is tough 2024-03-29 23:55:55 aaaugh 2024-03-29 23:55:58 gotta be a simple issue 2024-03-29 23:56:35 take a walk instead?