4

Are there reflection methods available in elisp to examine the stack without invoking the debugger?

For example:

  • Get the calling/callee function
  • Get the function call stack
  • Get the (longer) nested statement stack
  • Get arguments for any of the above

An aside: In my search for applicable features/functions/variables I was surprised to learn that elisp does not (natively) perform tail call optimization! Presumably elisp does then maintain a complete stack.

1
  • 1
    See called-interactively-p for a function doing this. I generally recommend against doing such a thing as it's error-prone, incredibly hard to read and lispy languages don't have the need for it.
    – wasamasa
    Jun 10, 2016 at 8:03

1 Answer 1

3

Short answer : the function backtrace-frame should be what you want.

How did I find this ? Well, here are the steps :

  1. invoke the elisp info manual (my favourite way is C-h r TAB RET), then
  2. search stack in the index via i stack RET.

The first result brings you to (info "(elisp) Internals of Debugger") which mentions backtrace-frame. I think this has all you want.

You can also look at the implementation of the debugger in debug.el, e.g. with M-x find-function RET debug RET if you have the sources installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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