For example,
(defun create-function (number)
`(lambda () (* ,number ,number)))
(defalias 'square-two (create-function 2) "adds two")
(square-two)
For example,
(defun create-function (number)
`(lambda () (* ,number ,number)))
(defalias 'square-two (create-function 2) "adds two")
(square-two)
Edebug does not support instrumenting code constructed at runtime. If you try to instrument create-function
, then the stepping will occur when you evaluate (create-function 2)
, not when you execute square-two
.
Edebug does support instrumenting lambda
forms though, so you can rewrite your example using lexical binding:
;;; -*- lexical-binding: t -*-
(defun get-lexical-function (number)
(lambda () (* number number)))
(defalias 'square-two (get-lexical-function 2) "adds two")
Then if you instrument get-lexical-function
before evaluating the defalias
form, you can step through the lambda
when evaluating square-two
.
Yes.
M-x debug-on-entry RET square-two RET
M-: (square-two) RET
Debugger entered--entering a function:
* square-two()
eval((square-two) nil)
eval-expression((square-two) nil nil 127)
funcall-interactively(eval-expression (square-two) nil nil 127)
call-interactively(eval-expression nil nil)
command-execute(eval-expression)
Use d
to step through the function. Use c
to skip through a step (skip substeps). And as always, C-h m
tells you more about the debugger, including other keys.
BTW, while npostavs's solution is the better option for your example, in those cases where you really do need to build the code manually with backquotes (e.g. inside defmacro
), you can try:
(defun create-function (number)
(edebug-\` (lambda () (* ,number ,number))))