Thought for the Day: Why do we have generic functions but
not generic slots?
(slot-value (plate1 plate2) 'capacitance) => 10
hmm... order dependency?
(setf (slot-value (fool priest) 'trust) 't)
(setf (slot-value (priest fool) 'trust) 'f)
David Golden wrote:
> Thought for the Day: Why do we have generic functions but
> not generic slots?
>
> (slot-value (plate1 plate2) 'capacitance) => 10
>
> hmm... order dependency?
> (setf (slot-value (fool priest) 'trust) 't)
> (setf (slot-value (priest fool) 'trust) 'f)
You probably mean (slot-value (list plate1 plate2) 'capacitance), etc.
This means that you want to express relations between objects. It's
already possible to do that by way of eql specializers:
(defmethod capacitance
((plate1 (eql *some-plate*))
(plate2 (eql *some-other-plate*)))
10)
You can also create these methods programmatically if you have a MOP at
hand. Or else, you simply place these relations in a hash table.
(defvar *trust-relationships* (make-hash-table :test #'equal))
(defmethod trust (p1 p2)
(gethash (list p1 p2) *trust-relationships*))
(defmethod (setf trust) (new-value p1 p2)
(setf (gethash (list p1 p2) *trust-relationships*) new-value))
...and combine them...
(defmethod trust ((anyboy person) (gwb (eql *george-w-bush*)))
nil)
BTW, generic functions are not called generic functions because you can
specialize on more than one parameter. They are just called so because
they work for more than one type.
Pascal
--
1st European Lisp and Scheme Workshop
June 13 - Oslo, Norway - co-located with ECOOP 2004
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
Pascal Costanza wrote:
> You probably mean (slot-value (list plate1 plate2) 'capacitance), etc.
>
Indeed. Though, arguably, you might need special specifier syntax instead
to e.g. distinguish ordered from unordered.
> This means that you want to express relations between objects.
Yes. Actually, I have a habit of sticking everything important in RDBMS and
avoiding "OO" in the first place, I find relational stuff makes more sense
to me than classes+objects, but hey.
> already possible to do that by way of eql specializers:
> You can also create these methods programmatically if you have a MOP at
> hand. Or else, you simply place these relations in a hash table.
>
Yeah, but they're a bit long-winded for something that I want to do a lot
(another approach: actually create a class, the (tracked) instances of which
represent the relationship, akin to creating a third table for a
many-to-many relationship in an RDBMS) so a standard shorter syntax might
be nice.
And I didn't think through inheritance or interaction with with-slots - i.e.
I'd want relationship slots to have the same standing as ordinary slots.
> BTW, generic functions are not called generic functions because you can
> specialize on more than one parameter. They are just called so because
> they work for more than one type.
>
Yes. I apologise for my incorrect usage there. Might have led some readers
to think I meant object able to have a slot of type A with the same name as
a slot of type B but with different value by virtue of the different type,
which is another can of worms.
In article <···················@news.indigo.ie>,
David Golden <············@oceanfree.net> wrote:
> Pascal Costanza wrote:
>
> > You probably mean (slot-value (list plate1 plate2) 'capacitance), etc.
> >
>
> Indeed. Though, arguably, you might need special specifier syntax instead
> to e.g. distinguish ordered from unordered.
>
> > This means that you want to express relations between objects.
>
> Yes. Actually, I have a habit of sticking everything important in RDBMS and
> avoiding "OO" in the first place, I find relational stuff makes more sense
> to me than classes+objects, but hey.
One way to compromise is to represent the connections themselves as
objects, e.g.:
(defclass connectable () (connections))
(defclass connection () (connectees))
(defclass trust-relationship (connection) trust)
(defmethod connect ((thing1 connectable) (thing2 connectable)
(conn connection))
(pushnew conn (slot-value thing1 'connections))
(pushnew conn (slot-value thing2 'connections))
(pushnew thing1 (slot-value conn 'connectees))
(pushnew thing2 (slot-value conn 'connectees)))
(defun make-trust-relationship (truster trustee trust-value)
(connect truster trustee
(make-instance 'trust-connection :trust trust-value)))
Or something like that.
Writing the code for (find-connection thing1 thing2 type) is left as an
exercise, as is modifying the code so that find-connection can be
implemented efficiently.
E.
"David Golden" <············@oceanfree.net> schrieb im Newsbeitrag
························@news.indigo.ie...
>
> Yes. Actually, I have a habit of sticking everything important in RDBMS
and
> avoiding "OO" in the first place, I find relational stuff makes more sense
> to me than classes+objects, but hey.
>
You might want to have a look at ap5 (at ap5.com).
This is a library that adds relational programming to lisp.
Rene.
Rene de Visser wrote:
> This is a library that adds relational programming to lisp.
>
Looks quite nice, but -
I can't find any licence statement? Under (imho wrong, but I'm not quite
ready to go to gaol over it) current law (intrinsic copyright via Berne
Convention, which I don't recall signing, though some assholes decided they
could sign it in my name), that means I can't use it.
(Well, more precisely, that I can't redistribute any code incorporating it,
but as a Free Software flaming hippie leftist rightist anarchist fascist
communist libertarian liberal pirate hybrid leprous Terrorist <insert
anti-Freedom propaganda drivel of your choice here> supporter, same
difference)
No, there isn't a license agreement with it.
I sent a couple of emails to Don Cohen last week about this.
But haven't heard back from the second one.
(I've been playing around with AP5 for about a year, but haven't concerned
myself with the licensing up until now).
Rene.
"David Golden" <············@oceanfree.net> wrote in message
························@news.indigo.ie...
> Rene de Visser wrote:
>
>
> > This is a library that adds relational programming to lisp.
> >
>
> Looks quite nice, but -
>
> I can't find any licence statement? Under (imho wrong, but I'm not quite
> ready to go to gaol over it) current law (intrinsic copyright via Berne
> Convention, which I don't recall signing, though some assholes decided
they
> could sign it in my name), that means I can't use it.
>
> (Well, more precisely, that I can't redistribute any code incorporating
it,
> but as a Free Software flaming hippie leftist rightist anarchist fascist
> communist libertarian liberal pirate hybrid leprous Terrorist <insert
> anti-Freedom propaganda drivel of your choice here> supporter, same
> difference)
>
>
>
>
>
>
>
>
>