On Saturday, 29 August 2015 22:41:49 UTC+1, Stefan Monnier wrote: > > Is there a built in way to return the arg list (actually just the number of > > args) for a function that has been passed to me? > > The answer is "yes, but fundamentally no". > The reason it's fundamentally no, is that you'd need to answer questions > such as "how many arguments does cl-member take". > > In most cases, the better approach is to do something else, such as: > > (condition-case > (funcall thefunction arg1 arg2 ...) > (wrong-number-of-arguments > ...do-something-else...)) This is only to answer a toy problem anyway so good to know this doesn't scale. I ended up doing this (defun args (function) "The arg list of FUNCTION." (let ((kind (car function))) (if (eq kind 'closure) (cadr (cdr function)) (cadr function)))) because the nature of the problem required working on a function with an arbitrary argument list. https://github.com/fommil/e99/blob/master/48.el I suppose I could re-interpret the question to take the nargs explicitly.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4