freenode/#lisp - IRC Chatlog
Search
8:28:57
elderK
Do you use generics and just say the thing? Like, instead of location-offset, you just have a generic called index, and specialize it for a location?
8:29:23
elderK
Do you change convention depending on context? If so, when, and what questions do you ask, what constraints, help you decide when to apply which?
8:31:17
beach
elderK: I skip the type thing. Not only because it becomes unwieldy, but also because it becomes really weird with subclassing. Take CLIM, for instance. It looks very strange to say (SHEET-PARENT PANE).
8:33:00
elderK
The next question comes to do with overloading, or the situation where say, you have a generic with a name that applies to many types, but in different ways.
8:33:18
elderK
I have seen the 'allow-other-keys' thing. I was wondering if and how that could be used to do this.
8:33:47
elderK
Say, one method expects two parameters, another expects one. But they are all the same generic.
8:34:36
beach
If you have a name that appears to apply to different, unrelated, types, then those types should probably go in different packages.
8:35:33
elderK
Which brings me to the next thing: Can each package define a generic with the same name?
8:36:25
no-defun-allowed
I use your "Scheme convention" for classes that have subclasses that introduce few concepts that the superclasses don't.
10:55:33
phoe
minion: memo for elderK: there also exist package-local nicknames that aid one with defining functionalities in multiple packages. You can use names like A:OFFSET, F:OFFSET, S:OFFSET, even if the packages are named e.g. FROB.ACCESSIBILITY, FROB.FUNCTIONALITY, FROB.SECURITY - PLNs do the translation.
15:36:03
sgithens
Hi all. I'm wondering if there is a way (or preferably nice way) to get a :predicate option for defclass similar to defstruct? I'm somewhat new, so I'm not sure if this would be lurking in an existing option, or needs to be a superclass, or metaclass that must be brought in.
15:38:04
beach
I think you either have to define it "manually", or you need some MOP manipulation to define a new metaclass, etc. It is probably not worth it.
15:44:12
sgithens
beach: Thanks, I'm actually bringing an old project back up to speed that I've inherited, and it has and uses `XYZed?` predicate tests for all it's classes, but I can't quite tell where they are coming from, I think it may have pulled in quite older versions of CLOS and things. Mostly I'm looking at how to properly replicate this on modern CL
15:47:05
beach
sgithens: It would be more common to use generic dispatch than to test for the type explicitly.
15:47:15
pjb
sgithens: a lighter way would be to define the predicate separately. (defclass foo …) (define-type-predicate foop foo)
15:47:48
pjb
sgithens: with a simplier (defmacro define-type-predicate (name type) `(defun ,name (x) (typep x ',type)))
15:52:52
sgithens
pjb: Thanks much! I may start with the less intrusive define-type-predicate here, as there are probably less than 30 classes I need to do this for. I fear I'm still new enough to CL to be a little initimated at shadowing the defclass, but will take a look at it :)
15:53:55
beach
sgithens: Like I said, a better way would be to use more generic functions rather than explicit tests for the type.
15:56:08
sgithens
beach: I'm guessing because it would handle more of the nuances for comparing class heirarchies and oddities with equality and whatnot?
16:01:28
beach
It is more a question of modularity. If you are using explicit tests in a function that has some action, then each class-specific action must be present in that function. So if you add some class you need to modify the function.
16:02:15
beach
If you use a generic function ACTION, and specialize it to different classes, the class-specific actions are physically separated, and you can put them in different modules.
16:04:04
beach
So instead of (defun action (x) (cond ((a-p x) (do-a x)) ((b-p x) (do-b x))...)) you get (defmethod action ((x a)) (do-a x)) (defmethod action ((x b)) (do-b x)) ...