2024-08-10 00:49:47 https://ibb.co/YRG470Y -- this is a preview of my Forth language 2024-08-10 00:49:50 do you like it? 2024-08-10 01:50:37 'This page doesnt exist' 2024-08-10 01:51:51 sorry: https://ibb.co/WFXzYwR here we go 2024-08-10 02:33:38 looks funny with # for keywords but I like it 2024-08-10 03:00:11 rendar: reason for not just using : and ; for def and enddef 2024-08-10 10:38:16 I've started ##roff on this network for discussing roff and related programs, if anyone is interested 2024-08-10 11:14:53 lf94, it must be used by people more accustomed with a def/end structure, but it suports also #: and #; 2024-08-10 11:15:17 neauoire, those # are special keywords that cannot be redefined 2024-08-10 18:21:34 I wrote the minimal roguelike in Forth last night: http://canonical.org/~kragen/sw/dev3/wander.fs 2024-08-10 18:22:22 I'm interested in suggestions for improvement, though I might only implement them in whatever I implement next instead of in this program 2024-08-10 18:23:08 there isn't any way in Forth 2012 to find the current time, is there? For random seeding 2024-08-10 18:24:15 There's https://forth-standard.org/standard/facility/TIMEandDATE 2024-08-10 18:35:09 oh, thanks! 2024-08-10 18:37:38 that lets me eliminate one of three Gforthisms from the program. I somehow didn't realize time&date was in the Forth standard 2024-08-10 18:37:55 the other two being `require` and `#!` 2024-08-10 18:38:37 I normally check https://forth-standard.org/standard/alpha 2024-08-10 18:40:35 #! is just to allow it to be run directly from the shell, I'd assume 2024-08-10 18:41:01 xentrac: you could eliminate the shebang/#! by invoking it as gforth wander.fs instead 2024-08-10 18:41:18 yes 2024-08-10 18:41:38 or from things that aren't the shell 2024-08-10 18:41:44 unjust: yes, I did do that previously before I learned Gforth supported #! 2024-08-10 18:42:19 : #! POSTPONE \ ; immediate 2024-08-10 18:42:29 That's gforth's definition 2024-08-10 18:43:19 yeah, that makes sense 2024-08-10 18:43:37 but unfortunately there isn't a way to use that information to make #! portable to other Forths 2024-08-10 18:43:53 because to work as a Unix magic number it has to be the first two bytes of the file 2024-08-10 18:44:05 postpone, \ and immediate are all in the standard 2024-08-10 18:44:16 so you can't put that definition before it 2024-08-10 18:44:22 All it's doing is treating the rest of the line as a comment 2024-08-10 18:44:25 I know 2024-08-10 18:44:29 Ah, I see what you mean 2024-08-10 18:45:05 to eliminate `require` I guess I'll add my own definition of `random` 2024-08-10 18:45:09 Does the shebang have to be the first line in the file? 2024-08-10 18:45:29 not just the first line, the first two bytes 2024-08-10 18:45:34 you can't even put a space before it 2024-08-10 18:47:18 ugh, https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use used to have information in this table about which LCG parameters were good ones 2024-08-10 18:48:32 now instead it refers you to primary sources 2024-08-10 19:11:44 MINSTD seems to be adequate for my purposes: 2024-08-10 19:11:45 1 value seed \ note that this LCG PRNG assumes at least a 32-bit Forth: 2024-08-10 19:11:45 : minstd ( -- rand ) seed 48271 m* 2147483647 sm/rem drop dup to seed ; 2024-08-10 19:18:35 so now http://canonical.org/~kragen/sw/dev3/wander.fs works properly in both Gforth and PFE 2024-08-10 19:19:04 thanks, GeDaMo! 2024-08-10 19:19:14 :) 2024-08-10 19:20:14 I'd first implemented MINSTD just using `mod` rather than `sm/rem` but I realized that that meant I was assuming a 64-bit Forth 2024-08-10 19:20:56 since `seed 48271 *` is going to produce the wrong answer on a 32-bit Forth in the cases where `2147483647 mod` matters 2024-08-10 19:23:25 I suspect the program might be better if I switched to representing (x, y) positions as a single offset 2024-08-10 19:27:50 I also wrote a C version in http://canonical.org/~kragen/sw/dev3/wander.c because Gforth can't build a standalone executable 2024-08-10 19:29:29 Because I'm not doing anything especially Forthy the C and Forth versions are about the same amount of code, but the C is formatted much more vertically, while the Forth is formatted more horizontally, arguably excessively so 2024-08-10 19:33:50 heh, I was going to say "but the Forth code is probably buffering its output" but strace says it isn't 2024-08-10 19:34:16 so redrawing the dungeon on the screen involves calling write(2) 48 times 2024-08-10 20:05:39 xentrac: do you prefer the single line style in wander.fs nowadays vs. what you did with midpoint.fs? 2024-08-10 20:05:55 s/single line/horizontally-biased/ 2024-08-10 20:55:09 hmm, well 2024-08-10 20:58:13 I think the style in midpoint.fs is *clearer* 2024-08-10 20:58:23 but where Forth really excels is in interactivity 2024-08-10 21:02:45 you don't normally have a single-stepping debugger like you do in C or C++ or Pascal 2024-08-10 21:03:16 in BASIC you have line numbers and you can interactively do things like "RUN 70" or sometimes "GOSUB 70" 2024-08-10 21:03:33 in Forth instead you can *name* your lines of code 2024-08-10 21:04:02 so you can run them one at a time by naming them, which is a lot like single stepping in a debugger 2024-08-10 21:06:46 and interactive testing and debugging is more important than in C because (at least so far for me) the code is harder to read, and you don't have a type system to catch your bugs 2024-08-10 21:08:14 so I tend more toward writing lots of small definitions so I can test them interactively now 2024-08-10 21:09:08 in https://asciinema.org/a/621404 I did a screencast of debugging a buggy implementation of the Babylonian square root algorithm 2024-08-10 21:10:50 that makes sense 2024-08-10 21:11:14 have you used dbg in gforth-itc? 2024-08-10 21:11:59 https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Singlestep-Debugger.html 2024-08-10 21:12:35 to debug wander for example: page dbg wander 2024-08-10 21:12:47 I haven't! thanks! 2024-08-10 21:13:02 i like that approach of stepping through words, word-by-word 2024-08-10 21:13:56 Code Complete recommended stepping through all the code you write in a debugger at least once 2024-08-10 21:14:04 which at the time sounded like a big hassle 2024-08-10 21:14:19 to me 2024-08-10 21:14:36 I still don't always do it in languages like C, but often I do 2024-08-10 21:14:45 I never do it in Python and JS 2024-08-10 21:15:12 if you're comfortable with your debugger of choice (or circumstance) it's worth it, at least with languages that end up being translated in byte or machine code 2024-08-10 21:15:27 i'm biased though, and sort of like debugging more than programming though 2024-08-10 21:16:04 I feel like the Forth style of very small definitions makes it less necessary 2024-08-10 21:18:08 i guess the trick is being able to think through your problem well enough to ultimately factor your solution into concise definitions that are ideally self-evident enough that it becomes obvious how everything should be threaded together - but i haven't mastered that ideal