1

In Common Lisp, there is a function called function-lambda-expression, which returns the LAMBDA form that defines a function (or NIL on implementations that compile everything to native code).

Is there a function in ELisp that does something similar?

  • 1
    symbol-function returns the actual function object for the argument symbol, which will then be displayed as its printed representation (either a lambda form or compiled byte-code, but you could load the uncompiled version of the library to avoid the latter). Is that the sort of thing you're after? – phils May 1 '16 at 9:05
  • @phils symbol-function can also (and will often) return an auto-load. That is the reason I hesitated to post a comment similar to yours. – Tobias May 1 '16 at 12:12
  • True. Or a symbol, if function indirection is happening. Or just whatever was jammed into the function cell for the symbol, really. – phils May 1 '16 at 12:35
  • You would need to follow the describe-function code to see how does it get the arguments of a function. I think it parses source code to do that (i.e. symbols have references to the location they are declared in). This isn't bulletproof, since functions declared by macros, who don't have a symbol assigned to them would pose a problem. – wvxvw May 1 '16 at 14:54
  • All these comments are good. Someone please consider consolidating them (or similar) into an answer. It's a good question, even if the answer might not be entirely satisfying. – Drew May 1 '16 at 23:45
2

symbol-function can return an actual function object for the argument symbol, which would be displayed as its printed representation (either a lambda form or compiled byte-code -- but you could load the uncompiled version of the library to avoid the latter).

More precisely, it returns the value of the symbol's function cell. Besides a function object, other common values are:

  • auto-load objects: C-hig (elisp) Autoload Type
  • symbols: (elisp) Function Indirection
  • keyboard macros: (elisp) Keyboard Macros

(Strictly speaking, I believe a function cell can contain any value, but some types are rather more expected than others.)

  • Are there opaque compiled function objects in Elisp, other than for those functions that are written in C? – Throw Away Account May 2 '16 at 13:26
  • I don't think so. AFAIK the only options are (elisp) Primitive Function Type (in C), and normal lisp functions (which are all ultimately lambdas). – phils May 2 '16 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.