Elisp get function arity?

梦想与她 提交于 2019-12-23 18:02:37

问题


I'd like to be able to do:

(function-arity (intern "expt"))

I googled up this solution https://github.com/emacsmirror/parser/blob/master/parser-fn.el

But it's using help-function-arglist, so it's not exactly straightforward. I'd like something more solid, preferably rock-solid.


回答1:


There's no such thing as a rock-solid function-arity. In most cases where people want it, what they really want is to call a function in different ways depending on how many arguments it accepts (because its signature is different in different Emacs versions, for example), in which case the approach of "try calling it with many arguments and catch the potential error" is about as good as it gets.




回答2:


Can't see anything wrong WRT help-function-arglist, which does it's job here.

While lambda-arity --pointed at-- seems to have some bugs still.

For example

(optional-arglist (memq '&optional arglist))

should rather use `member '&optional', which would return the remaining list, thus enable counting the elements left.



来源:https://stackoverflow.com/questions/17693187/elisp-get-function-arity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!