libera/#commonlisp - IRC Chatlog
Search
16:50:56
hhdave
If one has a standard-effective-slot-definition [as returned by class-slots] is there an easy way to see what class it comes from?
16:52:40
hhdave
(other than checking to see if it's one of class-direct-slots for each of the superclasses I suppose)
16:54:38
hhdave
So I guess I have to check if the name of the effective-slot-definition is the direct slots of a class and if not then check all the superclasses and so on?
16:56:30
hhdave
I have an instance and the slot name (obviously). I need to retrieve the slot value from elsewhere, but it's stored according to a DB table that it comes from.
16:57:22
hhdave
I know it could come from several classes - I think I would need to find the most, errr, 'super' one that it comes from and if it comes from a couple of equally high up ones then I think my whole system would break anyway!
16:58:23
hhdave
When I inspect the effective-slot-definition it seems to have a 'class' slot which seems to point to the class that I want, but that doesn't seem to have a method that I know of to access it. I don't know what would happen if I declare the slot in a subclass too.
17:01:52
hhdave
I suppose the only way is to walk up through the superclasses. I just checked the standard effective slot definition of a subclass which redeclares a slot it inherits (adding a type) and the 'class' in the inspector is now the subclass. I think my metaclass would somewhat break in this case anyway. Thanks beach
17:12:05
Bike
you apparently want the direct slot definitions that were merged into that effective definition?
17:12:25
Bike
usually what you do is define your own slot-definition classes, and just put whatever information you need in a slot of the effective slot definition
17:13:10
Bike
you can define a method on compute-effective-slot-definition to define how whatever information you want is merged from the inheritance
17:18:57
hhdave
Bike: ok. Putting the extra info into the slot-definition subclasses might be sensible. I'll get back to it next week. I have subclassed these slot definition classes. Thanks.
21:52:37
phoe
I have a list of numbers and I want to get a list of their sub-sums, so e.g. (1 2 3 4 5 ...) -> (1 3 6 10 15 ...)
21:54:25
moon-child
that's a prefix scan, which is a variant of reduce. I don't know of a specific implementation strategy, but you can use that keyword to search for one
21:55:43
jcowan
the nice thing about reduce over fold is that if you know the procedure is associative you can use a parallel algorithm.
22:01:16
edgar-rft
(let ((sum 0)) (mapcar (lambda (x) (incf sum x)) (list 1 2 3 4 5))) => (1 3 6 10 15)
22:04:11
edgar-rft
but code that I still can understand at the first read in hundred years from now...
22:48:30
jcowan
moon-child: No. The main difference is that you fold using a plain function and you reduce using a monoid.
22:49:48
jcowan
In a monoid, you always statically know the start value, instead of it being passed to the fold: thus the normal + monoid returns 0 if applied to zero arguments. Third, fold can be done in parallel because a monoid is guaranteed to be associative.
1:20:03
pjb
phoe: (mapcar (let ((s 0)) (lambda (i) (incf s i))) (iota 10)) #| --> (0 1 3 6 10 15 21 28 36 45) |#
1:26:29
moon-child
(actually, I would have expected the former to perform better, but sbcl seems to generate the same code for both)
1:32:14
pjb
If you look at the code of the minimal-compiler, (or just compiler), it would be obvious why the same is generated.