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

Identifying and Distinguishing Methods

1 view
Skip to first unread message

John Clonts

unread,
Nov 10, 2000, 2:00:08 AM11/10/00
to
I have two methods

(defmethod my-function ((x integer)) (cons x :integer))

(defmethod my-function (( n (eql 10) ))(cons 100 :hundred))

I see that I can refer to the first for example to trace it like:

(trace ((method my-function (integer))))

But how to do the same for the second, that has the "eql-specializer":

(trace ((method my-function (eql 10)))) ; doesnt work
Error: `(method my-function (eql 10))' is not fbound

Thanks,
John

P.S. Using acl6_trial

Kent M Pitman

unread,
Nov 10, 2000, 3:00:00 AM11/10/00
to
John Clonts <jcl...@mastnet.net> writes:

You should specify an implementation and version since
this is implementation-dependent, i.e., beyond the scope of the spec,
but doesn't

(trace ((method my-function ((eql 10)))))

work? (It does in LispWorks 4.1, for example.)

(Note that (method my-function (eql 10)), which you used, specifies
purported classes for two arguments, one of class EQL and one of class 10,
which of course aren't valid classes.)

John Clonts

unread,
Nov 10, 2000, 3:00:00 AM11/10/00
to
Kent M Pitman wrote:
> You should specify an implementation and version since
> this is implementation-dependent, i.e., beyond the scope of the spec,
> but doesn't
>
> (trace ((method my-function ((eql 10)))))
>
> work? (It does in LispWorks 4.1, for example.)
>
> (Note that (method my-function (eql 10)), which you used, specifies
> purported classes for two arguments, one of class EQL and one of class 10,
> which of course aren't valid classes.)

Kent,

Ok, thanks. I thought I had tried that but I see that it works for me.

Now I have been looking at find-method and remove-method, and notice
that they use a different means entirely for specifying the method:

(trace ((method my-function (integer))))
but
(find-method #'my-function nil (list (find-class 'integer)))

and

(trace ((method my-function ((eql 10)))))

but
(find-method #'my-function nil (list (mop:intern-eql-specializer 10)))


1) I couldn't really tell if the mop:intern-eql-specializer is standard,
or is it a Franz-ism (I'm using acl 6).

2) What is the role of "method" in the trace example above?

Thanks,
John

(mailed and posted an equivalent on c.l.l)

Barry Margolin

unread,
Nov 10, 2000, 3:00:00 AM11/10/00
to
In article <3A0C181E...@mastnet.net>,

John Clonts <jcl...@mastnet.net> wrote:
>2) What is the role of "method" in the trace example above?

It's similar to the role of "setf" in

(defun (setf xxx) ...)

Just as the name of a setf function is the list (setf <accessor>), the name
of a method is (method <gf-name> <qualifiers> (<arg-specializers>)).
However, while (setf ...) is part of the ANSI standard, (method ...) is an
implementation extension. It allows you to refer to methods in parameters
to macros like TRACE (since it doesn't evaluate its arguments, you can't
call MOP functions to look up the method).

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Steven Haflich

unread,
Nov 10, 2000, 3:00:00 AM11/10/00
to

John Clonts wrote:

> 1) I couldn't really tell if the mop:intern-eql-specializer is standard,
> or is it a Franz-ism (I'm using acl 6).

Symbols exported from the mop package are those specified by the
standard (but unofficial) definition of the CL metaobject protocol
specified in _The Art of the Metaobject Protocol_, Kiczales et al,
1991. In that sense, they are standard.

David Bakhash

unread,
Nov 10, 2000, 10:00:42 PM11/10/00
to
Steven Haflich <haf...@pacbell.net> writes:

I'd assume that symbols exported from the CLOS package are safe to
use. If it's an unexported symbol from the CLOS package, then I'd try
to avoid it.

dave

Robert Monfera

unread,
Nov 10, 2000, 10:24:04 PM11/10/00
to
John Clonts wrote:

> (trace ((method my-function ((eql 10)))))
> but
> (find-method #'my-function nil (list (mop:intern-eql-specializer 10)))
>

> 1) I couldn't really tell if the mop:intern-eql-specializer is standard,
> or is it a Franz-ism (I'm using acl 6).

MOP is described in a book titled The Art of Metaobject Protocol, and it
is a de facto standard. Intern-eql-specializer is part of it. The
reference says, "The result is the eql specializer metaobject for
object."

You can either get the AMOP book (being very educational, it's
recommended) or look at the reference part of AMOP in the MOP section of
the ACL documentation.

> 2) What is the role of "method" in the trace example above?

If you have the ACL documentation, take a look at the section on
function specs in implementation.htm. There are alternative functions
to specify, for example FLETs.

Robert

Pekka P. Pirinen

unread,
Nov 15, 2000, 3:00:00 AM11/15/00
to
John Clonts <jcl...@mastnet.net> writes:
> (find-method #'my-function nil (list (mop:intern-eql-specializer 10)))
>
> 1) I couldn't really tell if the mop:intern-eql-specializer is standard,
> or is it a Franz-ism (I'm using acl 6).

It's an AMOPism, as Steve Haflich said. It's not something you need
to use with any standard function, as the list (EQL <object>) is a
standard parameter specializer.
(find-method #'my-function nil (list '(eql 10)))
You might need it when calling some ACL MOP function.
--
Pekka P. Pirinen
Heard at OOPSLA 2000: We didn't pick the best solution [for the architecture],
because it would have required C++ programmers who understand the language.

John Clonts

unread,
Nov 15, 2000, 3:00:00 AM11/15/00
to
Pekka P. Pirinen wrote:
>
> John Clonts <jcl...@mastnet.net> writes:
> > (find-method #'my-function nil (list (mop:intern-eql-specializer 10)))
> >
> > 1) I couldn't really tell if the mop:intern-eql-specializer is standard,
> > or is it a Franz-ism (I'm using acl 6).
>
> It's an AMOPism, as Steve Haflich said. It's not something you need
> to use with any standard function, as the list (EQL <object>) is a
> standard parameter specializer.
> (find-method #'my-function nil (list '(eql 10)))

Excellent! This is what I was after. I suppose the reason I didn't
find it is because ACL complains:

Error: The generic function #<standard-generic-function my-function>
does not
have a method with qualifiers nil specializers ((eql 10))
[condition type: program-error]

But, I found that CMUCL worked as you said...

Cheers,
John

P.S. complete code follows

(defmethod my-function ((x integer)) (cons x :integer))

(defmethod my-function (( n (eql 10) ))(cons 100 :hundred))

(find-method #'my-function nil (list '(eql 10)))

Stig E. Sandø

unread,
Nov 17, 2000, 3:00:00 AM11/17/00
to
John Clonts <jcl...@mastnet.net> writes:

> Pekka P. Pirinen wrote:
> >
> > John Clonts <jcl...@mastnet.net> writes:
> > > (find-method #'my-function nil (list (mop:intern-eql-specializer 10)))
> > >
> > > 1) I couldn't really tell if the mop:intern-eql-specializer is standard,
> > > or is it a Franz-ism (I'm using acl 6).
> >
> > It's an AMOPism, as Steve Haflich said. It's not something you need
> > to use with any standard function, as the list (EQL <object>) is a
> > standard parameter specializer.
> > (find-method #'my-function nil (list '(eql 10)))
>
> Excellent! This is what I was after. I suppose the reason I didn't
> find it is because ACL complains:
>
> Error: The generic function #<standard-generic-function my-function>
> does not
> have a method with qualifiers nil specializers ((eql 10))
> [condition type: program-error]

I think this is a bug, ie the code below does not work with ACL6
trial (but I am pretty sure it worked with ACL5, and it works with
CLISP and CMUCL):

(in-package :cl-user)

(defpackage :biff
(:use :common-lisp)
(:export #:foo))

(defpackage :bobby
(:use :common-lisp :biff))

(in-package :biff)

(defgeneric foo (bar)
(:method :after (bar)
(warn "after")))

(in-package :bobby)

(defmethod foo ((bar (eql :xyzzy)))
(warn "xyzzy"))

;(foo :xyzzy)
;(in-package :cl-user)
;(biff:foo :xyzzy)CC
-----

It is kindof vital that this work because I do have interfaces in a
package :biff and separate implementations in :bobby-alike paclages.
Am I doing something wrong which I miss entirely? (The code works
when the method also is in package :biff)


--
------------------------------------------------------------------
Stig Erik Sandoe st...@ii.uib.no http://www.ii.uib.no/~stig/

0 new messages