libera/#commonlisp - IRC Chatlog
Search
5:56:31
beach
Also, the remarks by dbotton prompted me to work on my book project on CLOS programming (from which the chapter on protocols is extracted), but I am not sure how long I will keep up the enthusiasm now that my favorite coauthor has developed other interests.
5:59:58
beach
Maybe I should write the book openly so that people here can contribute. I'll give that some thought.
8:28:46
beach
dbotton: You you WHEN in a context where the value is needed. IF should be used then instead.
8:29:09
beach
dbotton: And you have several violations of the rules stated on page 13 of the LUV slides by Norvig and Pitman.
8:32:08
beach
dbotton: And since you have the same name for a slot and its reader, you suggest that it is OK to use SLOT-VALUE and WITH-SLOTS on it.
8:34:49
dbotton
I will do a full walk through after your comments to spruce it up. It for sure needs it, was my first CL program
8:44:31
beach
You can count on it, but in order to signal the intent to the person reading your code, you should use WHEN and UNLESS only in a context where the value is not used.
8:47:52
beach
See for instance: https://irclog.tymoon.eu/libera/%23commonlisp?around=1713974717#1713974717
8:48:57
beach
dbotton: Also, slots are implementation details. They may disappear as the result of maintenance.
8:49:27
beach
dbotton: As my document on protocols indicates, all access should be though (typically generic) functions.
8:51:31
dbotton
It should not have taken me that long to understand the idea coming to CL and near no documentation for it
9:00:19
dbotton
Beach I hope your CLOS book becomes a reality. There is a need for a well written practice as we understand it today books for idiomatic CL programming. I asked from start when learned of anything existed
9:42:18
pranav
beach: Thanks for the time you take out for this chatroom, not least for clarifying terminology, which I believe helps me read and understand CLHS and CLTL2 better.
15:01:03
beach
mwnaylor: Making it possible to add slots to individual instances would make it much harder to implement slot access efficiently. Have you seen this possibility in any other language?
15:12:34
bike
you might get this in a more free-wheeling prototype-based object system, like you get in javascript
15:19:40
beach
Sometimes a person will give as a reason something they heard from a friend, meant to be an argument against Common Lisp, without the person having considered the reason himself or herself.
15:22:05
beach
mwnaylor: The good news is that you can create such an object system in Common Lisp if you like. In fact, I think the GUI library (the name of which I forget) had such a system.
15:24:38
mwnaylor
beach: I was was wondering if it would be simpler to patch onto an existing object rather than extending a class. FWIW, I'm still new to CLOS.
15:24:44
bike
i thought one of the JSON libraries had some MOP business to match javascript objects, but i can't find it now
15:25:33
beach
mwnaylor: It is a somewhat strange thing to want to do in terms of software engineering. What is the use case here?
15:27:45
NotThatRPG
Is it possible to make a lisp file for sbcl that can be loaded into lisp OR used as a shebang script? Seems like LOAD won't like the shebang and bash won't like `;;; #!` but maybe there's a fix for this?
15:28:09
mwnaylor
Messing w/ internals of stumpwm. Guess I'll be better served by learing proper CLOS and delving into the stumpwm source code.
15:29:15
beach
mwnaylor: You can always stick the associated object in a hash table with the original object as a key.
15:29:22
NotThatRPG
bike: I tried to load such a file (inside a script for buildapp), and got an error...
15:40:56
paulapatience
NotThatRPG: https://github.com/Shinmera/wg-manager/blob/master/wg-manager.lisp
15:41:12
mwnaylor
beach: Interesting implementation. Clojure has defrecord, which allows adding new elements w/o changing the nature of the original object. Lisps dialects tend to be flexible about modifying data structures.
15:41:24
paulapatience
With a #||# comment you can have exec be the second line. By default executable scripts go through /bin/sh
15:45:04
bike
mwnaylor: in any case this doesn't seem like it does anything to individual objects, given that it defines a class
15:47:10
mwnaylor
bike: no, same type. The modified instance will still be acceptable to any functions related to a protocol. If the type changed, it would not be accepted as a valid parameter.
16:06:42
beach
mwnaylor: This is not hard to accomplish in a programming language. The hard part is to make it efficient. If you are not careful, each access to a field would require a hash-table lookup.
16:07:56
bike
it kind of looks like the object is a hash. i'm kind of curious how this is implemented. an actual java class with an extra field for a hash table of extra fields?
16:08:03
beach
mwnaylor: I am convinced that the designers of CLOS avoided this features because of such additional cost. But, again, an object system can be designed in, and added to, Common Lisp that has this feature. I wish I could remember the system that already did that.
16:08:32
bike
the docs mention an "extension field map" and a special field __extmap, maybe that's what those are
16:09:41
bike
https://cl-json.common-lisp.dev/cl-json.html#PROPERTIES-OF-FLUID-OBJECTS aha, this is the json thing i was thinking of
16:10:56
bike
https://github.com/sharplispers/cl-json/blob/master/src/objects.lisp#L96-L115 here's where setf on a missing slot is made to add a slot
16:13:09
mwnaylor
beach: Agreed (re: adding and making it efficient). Clojure has been designed to make this somewhat easy. That's why I was asking about something like an add-slot function that would modify an object.
16:14:29
beach
mwnaylor: OK, and CLOS has avoided it in the name of efficiency. You would have to use a different object system like Garnet to do that in Common Lisp.
16:14:55
beach
... but since you are working with existing code, that might not be possible of course.
16:20:44
mwnaylor
beach: I'll keep the hash table option in mind, though learning proper CLOS is probably the better option for *me*. Even with that option, would still have to explore the stumpwm source code. A lot of stuff in there that uses its own macros to define classes rather than simpler defclass inheritance.