all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: Re: ELisp function prototypes and local function name
Date: Thu, 07 Apr 2011 15:51:18 -0500	[thread overview]
Message-ID: <8739ltrdix.fsf@lifelogs.com> (raw)
In-Reply-To: 871v1erb9j.fsf@uwakimon.sk.tsukuba.ac.jp

On Thu, 07 Apr 2011 12:27:52 +0900 "Stephen J. Turnbull" <stephen@xemacs.org> 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




  parent reply	other threads:[~2011-04-07 20:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-06 13:36 ELisp function prototypes and local function name Ted Zlatanov
2011-04-06 15:19 ` Robert Pluim
2011-04-06 15:58   ` Ted Zlatanov
2011-04-07  0:25     ` Stephen J. Turnbull
2011-04-07  2:27       ` Ted Zlatanov
2011-04-07  3:27         ` Stephen J. Turnbull
2011-04-07  3:55           ` Jambunathan K
2011-04-07  5:43             ` Stephen J. Turnbull
2011-04-07 20:51           ` Ted Zlatanov [this message]
2011-04-08  4:01             ` Stephen J. Turnbull
2011-04-08  5:43               ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8739ltrdix.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.