Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Generic Slots

7 views
Skip to first unread message

David Golden

unread,
Jun 7, 2004, 1:17:23 PM6/7/04
to
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)


Pascal Costanza

unread,
Jun 7, 2004, 2:44:44 PM6/7/04
to

David Golden wrote:

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/

David Golden

unread,
Jun 7, 2004, 3:35:19 PM6/7/04
to
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.


Erann Gat

unread,
Jun 7, 2004, 3:49:50 PM6/7/04
to
In article <5o3xc.1660$Z14....@news.indigo.ie>,
David Golden <david....@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.

Rene de Visser

unread,
Jun 7, 2004, 4:29:57 PM6/7/04
to
"David Golden" <david....@oceanfree.net> schrieb im Newsbeitrag
news:5o3xc.1660$Z14....@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.


David Golden

unread,
Jun 7, 2004, 5:13:51 PM6/7/04
to
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)

Rene de Visser

unread,
Jun 8, 2004, 3:17:35 AM6/8/04
to
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" <david....@oceanfree.net> wrote in message
news:tQ4xc.1673$Z14....@news.indigo.ie...

0 new messages