Determining function argument list in Common Lisp

前端 未结 3 2125
自闭症患者
自闭症患者 2021-01-11 13:39

Is it possible to find out the argument list of a function, given a function object (or a function\'s symbol) in common lisp?

3条回答
  •  佛祖请我去吃肉
    2021-01-11 14:18

    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.
    #
    * (swank-backend:arglist #'testmethod)
    (ARG1 ARG2 &KEY (ARG3 :A))
    

    The easiest way to get Swank is to use Quicklisp.

提交回复
热议问题