[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ELisp function prototypes and local function name
From: |
Ted Zlatanov |
Subject: |
Re: ELisp function prototypes and local function name |
Date: |
Thu, 07 Apr 2011 15:51:18 -0500 |
User-agent: |
Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux) |
On Thu, 07 Apr 2011 12:27:52 +0900 "Stephen J. Turnbull" <address@hidden>
wrote:
SJT> Ted Zlatanov writes:
>> But it doesn't correspond to the advertised prototype
>> "(mapc FUNCTION SEQUENCE)" and loses the argument names.
SJT> Oh well.
SJT> (function-arglist 'mapc) => (mapc FUNCTION SEQUENCE &rest SEQUENCES)
SJT> where I live. I think Aidan Kehoe knows most about that code
SJT> currently, but I don't know what the assignment status is.
Interesting. So, disregarding the string-oriented help.el functions, in
Emacs we have `semanticdb-elisp-sym-function-arglist' which extracts the
actual function from the symbol:
#+begin_src lisp
(defun semanticdb-elisp-sym-function-arglist (sym)
"Get the argument list for SYM.
Deal with all different forms of function.
This was snarfed out of eldoc."
(let* ((prelim-def
(let ((sd (and (fboundp sym)
(symbol-function sym))))
(and (symbolp sd)
(condition-case err
(setq sd (indirect-function sym))
(error (setq sd nil))))
sd))
(def (if (eq (car-safe prelim-def) 'macro)
(cdr prelim-def)
prelim-def))
(arglist (cond ((null def) nil)
((byte-code-function-p def)
;; This is an eieio compatibility function.
;; We depend on EIEIO, so use this.
(eieio-compiled-function-arglist def))
((eq (car-safe def) 'lambda)
(nth 1 def))
(t nil))))
arglist))
#+end_src
but that returns nil for everything when I tried it. Also it calls
`eieio-compiled-function-arglist' which is:
#+begin_src lisp
(eval-and-compile
;; About the above. EIEIO must process its own code when it compiles
;; itself, thus, by eval-and-compiling outselves, we solve the problem.
;; Compatibility
(if (fboundp 'compiled-function-arglist)
;; XEmacs can only access a compiled functions arglist like this:
(defalias 'eieio-compiled-function-arglist 'compiled-function-arglist)
;; Emacs doesn't have this function, but since FUNC is a vector, we can just
;; grab the appropriate element.
(defun eieio-compiled-function-arglist (func)
"Return the argument list for the compiled function FUNC."
(aref func 0))
)
#+end_src
So `eieio-compiled-function-arglist' is what I need, but `aref' doesn't
work on any functions I've tried:
(aref (indirect-function 'mapcar) 0)
=> (wrong-type-argument arrayp #<subr mapcar>)
(aref (symbol-function 'mapcar) 0)
=> (wrong-type-argument arrayp #<subr mapcar>)
;; aref still doesn't work, but nth does on lambdas
(nth 1 (lambda (a b)))
=> (a b)
It looks like the XEmacs `function-arglist' is not useful, in any case.
It depends too much on the underlying implementation.
Ted
- ELisp function prototypes and local function name, Ted Zlatanov, 2011/04/06
- Re: ELisp function prototypes and local function name, Robert Pluim, 2011/04/06
- Re: ELisp function prototypes and local function name, Ted Zlatanov, 2011/04/06
- Re: ELisp function prototypes and local function name, Stephen J. Turnbull, 2011/04/06
- Re: ELisp function prototypes and local function name, Ted Zlatanov, 2011/04/06
- Re: ELisp function prototypes and local function name, Stephen J. Turnbull, 2011/04/06
- Re: ELisp function prototypes and local function name, Jambunathan K, 2011/04/06
- Re: ELisp function prototypes and local function name, Stephen J. Turnbull, 2011/04/07
- Re: ELisp function prototypes and local function name,
Ted Zlatanov <=
- Re: ELisp function prototypes and local function name, Stephen J. Turnbull, 2011/04/07
- Re: ELisp function prototypes and local function name, Ted Zlatanov, 2011/04/08