From d6d59c5551a16b5d81779de29e80ffa1065a4275 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 24 Mar 2017 19:55:53 -0700 Subject: trace: wrong function printed in traces. When tracing for two or more functions is enabled in a single trace form, the the function tracing hooks print the wrong name for all but the rightmost function. * share/txr/stdlib/trace.tl (sys:trace): Fix code which assumes that the each operator binds fresh lexical variables on each iteration. Bind a fresh lexical variable lex-n which copies the current value of the loop variable n, and refer to this lexical out of the tracing lambda. --- share/txr/stdlib/trace.tl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/share/txr/stdlib/trace.tl b/share/txr/stdlib/trace.tl index 940425c2..6aa80a46 100644 --- a/share/txr/stdlib/trace.tl +++ b/share/txr/stdlib/trace.tl @@ -35,18 +35,19 @@ (let* ((prev (or (symbol-function n) (throwf 'eval-error "~s: ~s does not name a function" 'trace n))) + (lex-n n) (hook (lambda (. args) (let ((abandoned t) (sys:*trace-level* (succ sys:*trace-level*))) (unwind-protect (progn - (sys:trace-enter n args) + (sys:trace-enter lex-n args) (let ((val (apply prev args))) - (sys:trace-leave n val) + (sys:trace-leave lex-n val) (set abandoned nil) val)) (if abandoned - (sys:trace-leave n :abandoned))))))) + (sys:trace-leave lex-n :abandoned))))))) (set [sys:*trace-hash* n] prev) (set (symbol-function n) hook))))))) -- cgit v1.2.3