libera/#commonlisp - IRC Chatlog
Search
23:07:42
doulos05
I've got a CLOS question. Say I've got two classes, (defclass a () ()) and (defclass b (a) ()). Each of these classes has slots, obviously B has all of A's slots because it inherit them.
23:08:38
doulos05
Is there a way I can use the `make-a` constructor I created (defun make-a (&key args go here) (make-instance 'a :args args :go go :here here)) directly inside the `make-b` constructor?
23:14:21
doulos05
The other thing I considered was just to make `a` a slot inside `b` (A is an empty tank you can select in the army building list and B is a tank on the battlefield, with crew stats, a location, damage, etc)
23:21:09
doulos05
But that feels like an extra level of misdirection because then I'm going to have to do things like (a/slot-accessor (b/a-slot b)) instead of just (a/slot-accessor b)
23:28:26
doulos05
Maybe I'm breaking this problem down wrong in my head? I'm certainly open to that possibility. I have tried several ways to structure this data in my head and I haven't yet arrived at one that I like. Let me switch to the actual class names.
23:29:33
doulos05
There's a lobby where you build your `FORCE`. To build this, you select `MEK`s from the list, which have their base stats. But you also assign pilots to them, you might choose to change the ammo loadout from the base load, etc.
23:30:55
aeth
instead of e.g. having tank subclassing tank-template, you can have tank-template as a slot
23:31:25
aeth
which is sort of like what you were saying earlier, except you're looking at it as empty-tank and tank
23:35:37
doulos05
You can also have multiple of the same MEK in an FORCE. Then, when the game begins, a MEK with a pilot, a location, etc is called a COMBAT-UNIT in the board game I'm emulating
23:37:31
doulos05
Ok, so then a COMBAT-UNIT has a MEK slot, and I'd have to just access all its stats with something like (mek/movement (cu/mek unit))
2:50:09
beach
doulos05: Many of us have come to the conclusion that it is not such a great idea to define specific constructors, even though Keene's book recommends them.
2:54:51
fosskers
beach: To clarify, you mean the `make-<structname>` functions that are auto-generated?
2:55:37
beach
No, I mean the make-<mumble> that you create your self and that do (make-instance '<mumble>...)
3:20:54
fosskers
Right, same thing just for structs/classes. What are the claimed benefits of custom constructors? Validation of input?
3:22:41
beach
I don't remember all the details. It's in Keene's book. Input validation I think is one aspect. Do you want me to look it up?
3:27:34
beach
We recommend that you define constructor functions to be used by the clients to make instances. A constructor is a tailored way to make an instance of a given class; its name usually describes the kind of instance it creates.
3:27:39
beach
A constructor provides a more abstract external interface than does make-instance, because its name describes its higher-level purpose (make a null lock) instead of its internal implementation (make an instance of the class null-lock).
3:27:45
beach
Another advante is that a constructor can have reqired arguments. In constrast, all arguments to make-instance except for the first are optional. We might prefer to require that users initialize thae name of a lock.
4:00:05
aeth
to me, the main downside of make-<foo> is that it encourages people to not export their class names
4:00:34
aeth
which doesn't give you the option of make-instance, but it also doesn't give you the option of check-type