tags:

views:

43

answers:

3

My application allows the user to create their own methods indirectly and I later need to refer to these methods. I am wondering if there is a way (for error checking purposes) to test if a method exists without trying to execute it. If I just try and call the method and it doesn't exist this will crash my application.

+3  A: 

It will not really crash, but signal a condition. If this condition is not handled, the debugger will be entered. See the CLHS, Section 9.1, for information on how to use the condition system.

Anyway, you can simply use fboundp for checking.

Svante
That's great thank you! Is there anyway to dissect the method returned by fboundp to determine what the class of the expected caller is supposed to be?
Mike2012
`fboundp` returns a generalized boolean, indicating whether a function of that name exists (I may have misinterpreted the intent of your question). The "class of the expected caller" is irrelevant; I guess you mean the specializers for the method. See Rainer's answer for that (using `find-method`).
Svante
+6  A: 

Also see the function FIND-METHOD : http://www.lispworks.com/documentation/HyperSpec/Body/f_find_m.htm#find-method

Rainer Joswig
+1  A: 

One solution would be to provide a "do nothing" GF method, dispatching on class T (the superclass of all classes). You'd need this for all GFs you're implementing methods on. It would also be possible to have that "do nothing" method log some data, maybe the class of each argument, for audit purposes.

Vatine