[英]How can I get function names defined in Lisp script?
I have a Lisp file with some functions defined [ (defun ... ]. 我有一个Lisp文件,其中定义了一些功能[(defun ...]。
Is there an easy way to get all function names defined in the script using Java? 是否有一种简单的方法来使用Java获取脚本中定义的所有函数名称?
也许您可以使用Java中的Small Lisp解释器中的一些代码
If you want to know, which functions are defined in a certain package, you cane use with-package-iterator
macro. 如果您想知道某个程序包中定义了哪些功能,可以使用with-package-iterator
宏。 Like this: 像这样:
(with-package-iterator (next (find-package 'test) :internal)
(loop :for (more? sym) := (multiple-value-list (next))
:if (fboundp sym) :collect sym :into rez
:else :unless more? :do (return rez)))
If you want to just extract functions from a script(-file), the easiest way seems to be scanning it with a regex "\\\\(defun (.+)\\\\s"
or something similar. 如果只想从脚本(-文件)中提取函数,则最简单的方法似乎是使用正则表达式"\\\\(defun (.+)\\\\s"
或类似的东西"\\\\(defun (.+)\\\\s"
对其进行扫描。
In very simple cases, you can use regular expressions. 在非常简单的情况下,您可以使用正则表达式。 In slightly less simple cases, implementing an S-expression reader might be a reasonable approach (you might even get away with ignoring reader macros altogether). 在不太简单的情况下,实现S表达式读取器可能是一种合理的方法(您甚至可以完全忽略读取器宏)。 In the general case, though, especially if macrology is involved, consider embedding Armed Bear Common Lisp , which is a Java implementation of Common Lisp, and using the with-package-iterator
form Vsevolod mentioned. 但是,在一般情况下,尤其是在涉及宏的情况下,请考虑嵌入Armed Bear Common Lisp (这是Common Lisp的Java实现),并使用提到的Vsevolod的with-package-iterator
形式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.