samedi 30 mars 2013

John Wiegley induced emacs [past]discovery of the day - edebug

EmacsConf is taking place today. John Wiegley speaks about elisp environment, including elp (profiler), edebug, and many other things. So I went to read the edebug manual a bit more (as usual I read a few pages but stopped too early).
I enjoyed the trace buffer combined with [fast]trace execution mode.

Enable the trace buffer with : `M-:` (setq edebug-trace t)

Now, let's say I have this in *scratch* (.|. being the caret)

(defun fact (n)
  (cond
   ((equal n 0) 1)
   ((* n (fact (- n 1))))))

.|.(fact 10)

`M-x` edebug-defun enters the elisp debugger

`T` will step through the s-exps in fast trace mode (automatically evaluate the next s-exp every N ms) and the *edebug-trace* buffer will trace the whole process nicely, resulting in this:

{ edebug-anon0 args: nil
:{ fact args: (10)
::{ fact args: (9)
:::{ fact args: (8)
::::{ fact args: (7)
:::::{ fact args: (6)
::::::{ fact args: (5)
:::::::{ fact args: (4)
::::::::{ fact args: (3)
:::::::::{ fact args: (2)
::::::::::{ fact args: (1)
:::::::::::{ fact args: (0)
:::::::::::} fact result: 1
::::::::::} fact result: 1
:::::::::} fact result: 2
::::::::} fact result: 6
:::::::} fact result: 24
::::::} fact result: 120
:::::} fact result: 720
::::} fact result: 5040
:::} fact result: 40320
::} fact result: 362880
:} fact result: 3628800
} edebug-anon0 result: 3628800

Kawaii, isn't it ?

Aucun commentaire:

Enregistrer un commentaire