2025-04-16 00:33:05 forth: : TEST DUP 0 = IF DROP 6 ELSE 1 - THEN DUP . ; 2025-04-16 00:33:08 forth: SEE TEST 2025-04-16 00:33:18 mforth: : TEST DUP 0 = IF DROP 6 ELSE 1 - THEN DUP . ; 2025-04-16 00:33:28 mforth: SEE TEST 2025-04-16 00:33:28 : TEST DUP 0 = IF DROP 6 BRANCH(9) 1 - DUP . ; 2025-04-16 00:33:33 bug ... 2025-04-16 01:02:44 mforth: see see 2025-04-16 01:02:44 Unknown word: see 2025-04-16 01:02:48 mforth: SEE SEE 2025-04-16 01:02:49 SEE: Unknown word: SEE 2025-04-16 12:01:37 Hi! 2025-04-16 12:03:57 I'm new to forth, and would like somebody to tell me how do I create "objects"? For example, say I want to have a box with different compartment. I'd like to name these like COMPARTMENT-A, COMPARTMENT-B, etc., so that I can set and retriever their values, while being able to allocate as many boxes as neded? wha't the forth way of doing that? 2025-04-16 12:06:51 I'm comming from C, so I'm referinf to the native way of doing data-structures in forth, because defining variables as offsets into a given array works for any array I'd like to use these, but I don't think that how it should be done 2025-04-16 12:13:14 Forth is very basic and "baremetal." Any of the things you just mentioned can be done, but you have to construct it, pretty much from scratch. Some Forths have more features than others, but in some cases you'll have to implement the memory management primitives, etc. But Forth does let you create "data storage structures" that have programmable actions associated with them. So it's definitely 2025-04-16 12:13:17 possible to set things up so that you can put a "message" on the stack, and then execute the data storage word, and the code associated with it will use that stack value to decide what to do. 2025-04-16 12:13:50 The mechanism for making that kind of word is called CREATE / DOES>; generally you write a word for creating your objects along these lines: 2025-04-16 12:14:23 : maker DOES> ; 2025-04-16 12:15:11 There are some efforts out there toward "object oriented Forths" you could either use or read to get ideas. 2025-04-16 12:15:33 <_guanche > thanks, but is this a common paradigm when writing forth or maybe I'm getting it all wrong? 2025-04-16 12:16:21 Well, some people definitely are interested in such things. But no, I wouldn't say it's the "most common" way of using Forth. Forth pre-dates object oriented ideas by quite a long time. 2025-04-16 12:16:36 <_guanche > by the way, I'm using SmithForth, so the low level thing is not a problem for me 2025-04-16 12:16:40 It's a very "procedural" language. 2025-04-16 12:17:33 Ok. Some folks are just "put off" by having so many things they're accustomed to having be built in not be. 2025-04-16 12:17:53 <_guanche > so, if you were to write, say a ternary tree, how would you go about it? (you'd need to allocate as many nodes as characters any stirng interned would have, and you might need to access each of these node's internal offsets 2025-04-16 12:18:02 A notable one is that often Forth doesn't even have much in the way of string support. You get to build that yourself too. 2025-04-16 12:19:40 Well, I'm not sure I fully see what that would require, but if you need a word for every character in a string, somewhere you'd have to write code to scan that string, iterate through it's characters, use your memory allocator to make a node for each one, link them together, etc. It would have to be built all the way up from the very bottom. 2025-04-16 12:20:26 Some Forths let you at least express a string as s" ". That leaves an address where the string is on the stack. 2025-04-16 12:20:55 Do note the space between s" and the string, so that it's a space delimited word. 2025-04-16 12:21:09 <_guanche > yes, I understand that, but what I mean is, in this case, a "Node" would need to keep the character it refers to, a two other pointers (because it's a ternary tree, so you need left and right pointers). I would need to access all these, for every node I'd need to allocate 2025-04-16 12:21:55 Yes. The usual way of doing that is that once you get the address of the node you then get to the fields yourself by adding the right offset. 2025-04-16 12:22:18 But everything in there you access using c@ or @ etc. and treating as a character or an integer etc. 2025-04-16 12:22:31 There aren't any built ins for "fields," or "types." 2025-04-16 12:23:03 Well, I say that, but that's another thing some people have tried to extend. It's just not standard. 2025-04-16 12:23:12 <_guanche > do you happen to know of an example of something like this I could look at, a binary tree or something close? 2025-04-16 12:23:35 <_guanche > I'm not actually willing to extend, but rather to use with what I have 2025-04-16 12:24:10 <_guanche > or said otherwise, to learn forth as it is, I'll worring about extendin it later 2025-04-16 12:24:21 No, I'm sorry - I'm not terribly familiar with the landscape out there. I tend to write my own Forths. I've done some singly and doubly linked lists, but I haven't done much with trees. I've thought about using b* trees to do a file system, but I've not actually done it. 2025-04-16 12:24:46 But it feels like something someone else here likely has seen somewhere. 2025-04-16 12:24:55 <_guanche > linked lists could keep me going, do you happen to have publicly available code? 2025-04-16 12:25:56 Nn, not personally; I'm sorry. Most of the US guys here are probably still sleeping, but there are some folks across the pond that hang out here too - hopefully someone else will be able to help you. 2025-04-16 12:26:00 <_guanche > tree are just "linked lists" with an extra field for data 2025-04-16 12:26:05 Yes. 2025-04-16 12:26:29 <_guanche > no problem, thanks so much. I'll look for linked lists out there to see what I can find 2025-04-16 12:26:50 Hey, good luck. Sounds like a fun application. 2025-04-16 12:27:12 <_guanche > thanks :D 2025-04-16 12:28:03 <_guanche > I always use ternary trees for language tokens and such, are quite efficient, so it's the first thing I'd like to modify in SmithForth 2025-04-16 15:58:19 It's the sort of thing I'd just think about for a while, to decide exactly how I wanted my tree nodes laid out in memory, and then just build up from the bottom, bit by bit. Some kind of a heap to let me allocate and free the nodes, then the usual things, add a node, delete a node, etc. Clearly you've got a good picture of what you want to do, so my bet is you won't have a whole lot of trouble 2025-04-16 15:58:22 putting it together. 2025-04-16 15:58:30 Just a bunch of tedious bits to tend to. 2025-04-16 15:59:32 Since your nodes will all be the same size (I think), the memory allocator will be pretty easy - I've done simple fixed size allocators several times - usually I just have a "frontier" variable I can push up as I need new space and a free list pointer. 2025-04-16 16:00:05 Then it's just a matter of how fancy I want to try to get, like do I also pull the frontier BACK when it's possible to do so, etc. 2025-04-16 17:15:21 mforth: LOAD "test.fth" 2025-04-16 17:15:27 mforth: LOAD "test2.fth" 2025-04-16 17:15:39 mforth: SEE CAL 2025-04-16 17:15:40 : CAL 2DUP SWAP MONTH-NAME DROP 32 EMIT NUM-TO-STR CR ." Mo Tu We Th Fr Sa Su " CR 2DUP ZELLER DUP 0 = IF DROP 6 ELSE 1 - THEN DUP OFF ! OFF @ 0 > IF OFF @ 0 DO 32 EMIT 32 EMIT 32 EMIT LOOP THEN DROP 2DUP 2DUP DAYS-IN-MONTH 1 + 1 DO I 10 < IF 32 EMIT 32 EMIT ELSE 32 EMIT THEN I NUM-TO-STR OFF @ I + 7 MOD 0 = IF CR THEN LOOP 2DROP CR ; 2025-04-16 17:15:49 fix issue with SEE 2025-04-16 17:17:08 should recompile words of SEE with no errors 2025-04-16 17:17:22 mforth: : CAL 2DUP SWAP MONTH-NAME DROP 32 EMIT NUM-TO-STR CR ." Mo Tu We Th Fr Sa Su " CR 2DUP ZELLER DUP 0 = IF DROP 6 ELSE 1 - THEN DUP OFF ! OFF @ 0 > IF OFF @ 0 DO 32 EMIT 32 EMIT 32 EMIT LOOP THEN DROP 2DUP 2DUP DAYS-IN-MONTH 1 + 1 DO I 10 < IF 32 EMIT 32 EMIT ELSE 32 EMIT THEN I NUM-TO-STR OFF @ I + 7 MOD 0 = IF CR THEN LOOP 2DROP CR ; 2025-04-16 17:17:35 mforth: 4 2025 CAL 2025-04-16 17:17:35 April 2025 2025-04-16 17:17:36 21 22 23 24 25 26 27 2025-04-16 17:17:36 28 29 30 2025-04-16 17:36:40 mforth: 88 40 MULTI-CHAR 2025-04-16 17:36:40 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 2025-04-16 17:37:08 fine to edit your stats 2025-04-16 17:43:44 cleobuline: no today word? 2025-04-16 17:45:03 i do not hilith the current day sorry 2025-04-16 17:45:40 you whant today word ? 2025-04-16 17:46:11 no, I was curious 2025-04-16 17:46:21 you have the tools 2025-04-16 17:46:27 mforth: MILLI 2025-04-16 17:46:34 mforth: .S 2025-04-16 17:46:35 <4> 4 2025 4 1744818387862 2025-04-16 17:46:54 so you can convert in todat date 2025-04-16 17:47:11 unix epoch? 2025-04-16 17:47:14 yes 2025-04-16 19:48:36 mforth: LOAD "test2.fth" 2025-04-16 19:49:06 mforth: TODAY .S 2025-04-16 19:49:06 <7> 4 2025 4 1744818387862 16 4 2025 2025-04-16 19:49:22 mforth: CLEAR-STACK 2025-04-16 19:49:25 mforth: TODAY .S 2025-04-16 19:49:25 <3> 16 4 2025 2025-04-16 19:49:33 happy anthk_ ? 2025-04-16 19:50:01 a piece of shit to calculate 2025-04-16 19:50:53 ew 2025-04-16 20:00:35 one time i needed the current date and only had seconds since UNIX epoch, looked up a way to calculate the date, after about an hour of trying to understand the solution i threw my code away and just used a library... 2025-04-16 20:00:55 mforth: LOAD "test2.fth" 2025-04-16 20:00:55 Unknown word in definition: NUM-TO-STR 2025-04-16 20:00:56 Error: Definition discarded due to error 2025-04-16 20:00:56 Unknown word in definition: NUM-TO-STR 2025-04-16 20:00:57 Error: Definition discarded due to error 2025-04-16 20:00:57 Unknown word in definition: NUM-TO-STR 2025-04-16 20:00:58 Error: Definition discarded due to error 2025-04-16 20:00:58 Unknown word in definition: NUM-TO-STR 2025-04-16 20:00:59 Error: Definition discarded due to error 2025-04-16 20:01:04 right 2025-04-16 20:01:07 mforth: LOAD "test.fth" 2025-04-16 20:01:12 mforth: LOAD "test2.fth" 2025-04-16 20:01:25 mforth: SEE TODAY 2025-04-16 20:01:25 : TODAY MILLI 1000 / 86400 / DAYS ! CALC-YEARS CALC-MONTHS CALC-DAY DAY @ MONTH @ YEAR @ ; 2025-04-16 20:01:51 mforth: SEE CALC-MONTHS 2025-04-16 20:01:51 : CALC-MONTHS 1 MONTH ! BEGIN DAYS @ 0> WHILE MONTH @ 2 = IF 28 ELSE MONTH @ 4 = IF 30 ELSE MONTH @ 6 = IF 30 ELSE MONTH @ 9 = IF 30 ELSE MONTH @ 11 = IF 30 ELSE 31 THEN DUP DAYS @ >= NOT IF DAYS @ SWAP - DAYS ! MONTH @ 1 + MONTH ! ELSE DROP EXIT THEN REPEAT DROP ; 2025-04-16 20:01:56 lol 2025-04-16 20:02:29 identity: you are curious :) 2025-04-16 20:03:07 yes i do it in 2 hours :) 2025-04-16 20:04:42 mforth: TODAY CAL 2025-04-16 20:04:42 April 2025 2025-04-16 20:05:04 mforth: LOAD "test2.fth" 2025-04-16 20:05:07 mforth: TODAY CAL 2025-04-16 20:05:08 April 2025 2025-04-16 20:05:08 21 22 23 24 25 26 27 2025-04-16 20:05:28 next i have to hilight today :) 2025-04-16 20:07:20 yay! 2025-04-16 20:08:02 identity: oh, you don't understand Zeller's congruence either? I'm not sure even Zeller did 2025-04-16 20:08:22 mforth: SEE ZELLER 2025-04-16 20:08:22 : ZELLER >R DUP 3 < IF 12 + R> 1 - >R THEN R@ 100 MOD R@ 100 / SWAP DUP 4 / + SWAP 2 * 0 SWAP - + SWAP 1 + 13 * 5 / 1 + + R> 100 / 4 / + 6 + 7 MOD ; 2025-04-16 20:10:53 mforth: 4 2 2025-04-16 20:10:53 mforth: 4 2025 ZELLER . 2025-04-16 20:10:53 identity: van Emden (PBUH) wrote a really interesting post about the transition from the "formulaic paradigm" exemplified by Zeller's congruence to a new "algorithmic paradigm": https://vanemden.wordpress.com/2010/11/29/from-formulas-to-algorithms/ 2025-04-16 22:56:04 mforth: LOAD "tes2.fth" 2025-04-16 22:56:04 Error: Error: LOAD: Cannot open file 'tes2.fth' 2025-04-16 22:56:09 mforth: LOAD "test2.fth" 2025-04-16 22:56:37 mforth: TODAY CAL-IRC-HIGHLIGHT 2025-04-16 22:56:37 April 2025 2025-04-16 22:56:38 21 22 23 24 25 26 27 2025-04-16 22:56:38 28 29 30 2025-04-16 22:56:51 it works only with irssi 2025-04-16 22:57:11 on my macos client it look italic 2025-04-16 23:00:07 does someone look different ? 2025-04-16 23:01:39 I see 16 in reverse video: 16 which is to say that instead of being orange on black it's black on a little orange square 2025-04-16 23:01:51 ok 2025-04-16 23:02:32 so it works :) 2025-04-16 23:04:51 on my macos client i see 16 in italics 2025-04-16 23:05:39 so yo usaid 2025-04-16 23:05:55 je radote ...