2024-02-07 09:28:11 Hey all! Hope this is the right place to ask - feel free to redirect me somewhere otherwise! What's an idiomatic way to design objects in Forth? Here's an example: I'm designing a text editor. In there, I can manage "panes" and "windows" of text. Those components can both be "create"d. However, the way to create a pane is different than the way to create a window. I've been thinking about two approa 2024-02-07 09:28:41 approaches so far: 1. Have 2 words, "create-pane" and "create-window" 2. have a single "create" word, that will grow whenever a new type of component can be built. 3. Still have a single "create" word, but pass on the stack a vector to be executed. Curious to know how you all approach such a problem usually. Thank you! 2024-02-07 09:29:35 Oh and one clarification: I'm not looking for an object-oriented lexicon/extension -- rather just understanding what's an idiomatic way to design such systems 2024-02-07 11:46:24 m15o: I tend to prefer the first approach 2024-02-07 12:46:30 Yes, the first is more "Forth-ish". 2024-02-07 14:03:21 thank you! 2024-02-07 16:16:14 m15o: just thought I would mention you might take a look at zeptoforth's oop implementation, in the docs/words/oo.html file. 2024-02-07 16:16:21 https://github.com/tabemann/zeptoforth 2024-02-07 16:17:04 The major deficiency I see right away about their oo implementation, however, is that each class can only have one superclass 2024-02-07 16:17:53 in lisp I find it is frequently useful to attach multiple superclasses to a class 2024-02-07 16:18:28 ACTION dispenses with classes altogether 2024-02-07 16:19:46 yeah, yeah, maybe some hostility around here to oop. but being able to attach interfaces to a class of objects, and implement methods, is a very powerful and practical tool 2024-02-07 16:20:19 implement specialized methods, I mean 2024-02-07 16:20:27 basically I have constructors and relie on delegation and composition 2024-02-07 16:21:54 Zarutian_iPad: do you blog post or something where you elaborate on that? 2024-02-07 16:22:59 I have not written an article on it but I did describe my object system here a few weeks or months back 2024-02-07 16:23:36 Zarutian_iPad: you should write up something, maybe copy and paste from your earlier thoughts 2024-02-07 16:25:15 I pretty much just adapted what folks at Agoric.com and erights.org do to rather forthish way 2024-02-07 16:25:57 sounds like the makings of an interesting post 2024-02-07 16:26:21 an object in this system is made up of four parts, header, xt, refs part, data part 2024-02-07 16:27:11 refs part is just the reference that object holds to other objects, data is pretty much any scalar or such data 2024-02-07 16:27:41 made garbage collection and such much easier to write 2024-02-07 16:28:55 and XT? 2024-02-07 16:29:29 the xt points to an forth word that handles invocations to the object which is of the form ( ... arg argnum verb pointer2object ) on stack 2024-02-07 16:30:34 so it is very similiar to the CREATE (or BUILDS> ) DOES> in design 2024-02-07 16:31:37 can you specialization in the system? reimplement an interface with a specialized object? 2024-02-07 16:32:42 sure, that object would have a method invocation handler xt all to itself 2024-02-07 16:33:38 the method invocation handler can dispatch on the verb in anyway it sees fit 2024-02-07 16:34:52 usually I just have the verb by some element of an system wide verbs enum and use a jump table 2024-02-07 16:35:11 do you have to reimplement all methods or can methods be inherited somehow? 2024-02-07 16:36:47 I can have an method handler that just checks for one verb and then just jump to an diffrent method handler for the rest 2024-02-07 16:37:37 so delegation and composition in both code and objects 2024-02-07 16:38:58 okay, sounds interesting, but it is not very clear at this point. If you had explanation/examples in one document or module description, it would be interesting to read that 2024-02-07 16:39:54 so basically every object has an xt that points to a "script" which is what you get after compositing all the methods together of an "class" 2024-02-07 16:40:58 I have not gotten to making this kind of "class" composition system 2024-02-07 16:41:39 why? most of the objects have at most dozens of methods 2024-02-07 16:43:13 hmm, so it sounds like you are composing interfaces? 2024-02-07 16:43:42 why did I write this object based system? I wanted to do compoitional graphics and ui in forth without taking up much memory 2024-02-07 16:44:25 well, the concept of class or interface doesnt exists on this level in this object based system 2024-02-07 16:46:12 sure I have three "interfaces" so far in the gfx stuff but they are only documented in a comment and not machine readably defined 2024-02-07 16:47:25 one such interface is the pixmap/bitmap interface, which has four method signatures defined 2024-02-07 16:48:02 getWidth, getHeight, putPoint, and getPoint 2024-02-07 16:48:59 and it is not only pixmaps, or bitmaps that implement it but various graphics transforms too 2024-02-07 16:51:07 one of the simplest is the translate transform that just adds offsets to the coordnates given in putPoint and getPoint, and then just forwards that modified invocation to the thing the transform objects has an reference to 2024-02-07 16:52:24 colour space transforms works in a similiar way but with the colours gotten or putted 2024-02-07 16:55:12 oh, and in the case of the translate transform the getWidth and getHeight are just delegated directly to the 'pixmap' the transform object has reference to 2024-02-07 16:55:55 what kind of project is this used in? 2024-02-07 16:56:16 ya got a foggy idea how the object system works now? 2024-02-07 16:57:11 mostly just me playing around and see how I could get it to work 2024-02-07 16:57:13 I think some of the ideas are coming across, but the system as a whole is not clear 2024-02-07 16:58:34 probably because the object system is so simple and small 2024-02-07 16:59:36 the objects live in one space seperate from the usual forth dictionary 2024-02-07 17:01:10 it doesn't sound bad, as far as I've been able to grasp it so far. Of course, there might be a lot of things missing that I'd want from an object system 2024-02-07 19:37:28 Zarutian_iPad: How are you using IRC on your iPad? I got one recently but the app store gave me pretty questionable stuff. 2024-02-07 19:37:56 Oh, sorry for going off topic :| 2024-02-07 19:39:26 web.libera.chat in safari 2024-02-07 19:40:11 Oh, forgot the webchat exits. That should work, thanks! 2024-02-07 19:44:34 user51-iPad: fwiw, i run irssi in a screen session and reattach it from an ssh client 2024-02-07 19:47:12 zelgomer: Can also work, I think webchat would sufice for now. 2024-02-07 20:47:29 the default vim syntax for forth is heinous 2024-02-07 21:02:12 Time to turn syntax off :) 2024-02-07 21:04:26 I solved it by instead using vi and compiling color support out of the terminal 2024-02-07 21:05:56 Or maybe use ed, if you keep your words short it should work great 2024-02-07 21:07:05 https://thrig.me/tmp/git-editor.txt 2024-02-07 21:07:33 Haven't used this one in a while http://0x0.st/HkdU.jpg 2024-02-07 21:10:31 busybox vi is ince 2024-02-07 21:10:43 although openbsd's vi has a special place in my heart 2024-02-07 21:10:46 er, s/ince/nice 2024-02-07 21:23:18 echo setl syntax= >~/.vim/after/syntax/forth.vim # problem solved