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?

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 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 01 '16 at 09: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 01 '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 01 '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 01 '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 01 '16 at 23:45
  • @phils, `symbol-function` is what I was looking for, thanks. – Throw Away Account May 02 '16 at 04:45

1 Answers1

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.)

phils
  • 48,657
  • 3
  • 76
  • 115
  • Are there opaque compiled function objects in Elisp, other than for those functions that are written in C? – Throw Away Account May 02 '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 02 '16 at 21:52