Is it possible to find out the argument list of a function, given a function object (or a function's symbol) in common lisp?
This is different for each CL implementation but the Swank package (provides Slime which can show arglists in f.e. Emacs' minibuffer) wraps this up in a single function:
* (defun testfn (arg1 arg2 &key (arg3 :a)) (declare (ignore arg1 arg2 arg3)))
TESTFN
* (swank-backend:arglist #'testfn)
(ARG1 ARG2 &KEY (ARG3 :A))
This will also work for methods:
* (defmethod testmethod ((arg1 t) arg2 &key (arg3 :a)) (declare (ignore arg1 arg2 arg3)))
STYLE-WARNING: Implicitly creating new generic function TESTMETHOD.
#<STANDARD-METHOD TESTMETHOD (T T) {1005670231}>
* (swank-backend:arglist #'testmethod)
(ARG1 ARG2 &KEY (ARG3 :A))
The easiest way to get Swank is to use Quicklisp.
ANSI Common Lisp provides the function FUNCTION-LAMBDA-EXPRESSION, which may return a lambda expression if the implementation supports it and the expression has been recorded. In the lambda expression, the second item is the argument list - as usual.
Otherwise to return an argument list is not defined in the ANSI Common Lisp standard and is part of the specific Lisp implementation. For example in some 'delivered' Lisp applications this information may not be present.
Typically most Common Lisp implementations will have an exported function ARGLIST in some internal package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With