确定Common Lisp中的函数参数列表 [英] Determining function argument list in Common Lisp

查看:53
本文介绍了确定Common Lisp中的函数参数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定函数对象(或函数的符号)时,是否有可能找出函数的参数列表?

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

推荐答案

这对于每个CL实现都是不同的,但是Swank程序包(提供了可以在fe Emacs的minibuffer中显示arglist的Slime)将其包装在一个函数中:

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))

这也适用于方法:

* (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))

获取Swank的最简单方法是使用 Quicklisp .

The easiest way to get Swank is to use Quicklisp.

这篇关于确定Common Lisp中的函数参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆