3 ms·
Old McCarthy Had a Form
- corvettez0606 5y agoEieio
- Nzen 5y agotl;dr describes a reimplementaton [0] of the Common Lisp Object Library System for emacs lisp. This allows using object-oriented strategies in emacs lisp scripts that might otherwise involve more abstract / lower level work over primitive lists for structure [1]. The title seems to be a reference to the 'form' package of the tool. [0] https://www.gnu.org/software/emacs/manual/html_mono/eieio.html https://www.gnu.org/software/emacs/manual/html_mono/eieio.ht... [1] To be clear, I've used CL only briefly. I'm only aware of emacs lisp by reputation. I don't doubt that experienced lispers are comfortable structuring their information as lists of lists and atoms.
- dreamcompiler 5y ago> I don't doubt that experienced lispers are comfortable structuring their information as lists of lists and atoms. I'm a very experienced Common Lisper and I very rarely use lists of lists except for small, incidental purposes. The Common Lisp Object System (as well as defstruct, arrays, hash tables, etc.) exists because lists -- while quite flexible -- are an extremely poor data structure for anything complicated because they make code almost impossible to understand and maintain. Using lists for everything is considered very poor Lisp programming practice -- at least by me.
- jinwoo68 5y ago"Form" is not only the package name of the tool but also a general term in Lisp that refers to S-expressions in the code.
- galaxyLogic 5y ago> CLOS classes only have fields ("slots," in CLOS parlance) — no methods. Does this mean that when you instantiate a class you get an "object" with only "slots". To interact with such objects there needs to be a way to read and write slot-values. Does that mean there is no way to prevent anybody from writing and reading any slot of any object?
- podiki 5y agoIf I'm remembering CLOS, that is correct. In general CL lets you do what you want, but convention would be to use accessor methods rather than the raw slot-value function that will work for any class and slot. See, for instance, https://gigamonkeys.com/book/object-reorientation-classes.html https://gigamonkeys.com/book/object-reorientation-classes.ht...
- juki 5y agoIn CL, slots are named by a symbol, and anyone can access it if they have access to the symbol. Symbols however are, by default, internal to a package (~namespace). Internal symbols won't be included when someone imports the package to another one. They can still be used from outside the package, but it requires explicitly using the double-colon `package::symbol`-syntax.
- galaxyLogic 5y agoSo what do you have outside the module that allows you to get or set the value of a slot? A function per slot written inside the module that owns the symbols? I know that in JavaScript ES6 you can define symbols that are private to the module which defines them which can effectively encapsulate data inside object-instances. That works best with an ES6 classes which have methods which are public but which can then access the data via those module-private symbols.
- juki 5y ago> A function per slot written inside the module that owns the symbols? Yes, usually you define accessors/readers for the slots that you want to be available to others. An accessor is basically a function that can be used like a variable, but allows arbitrary code to run when getting/setting it (this is important to allow macros to be written without having to constantly worry about whether something is a function call or a variable). The `defclass` macro has an option to automatically generate accessors, readers or writers for the simple case (just directly reading/writing the slot), but you can also define more complex ones by hand. You could of course also export the symbol to allow direct access to the slot, but accessors are the typical choice.
- snovv_crash 5y agoI clicked on the link expecting something about communist purges...