From: Aleksandr Vinokurov on 20 Apr 2010 16:23 Hello all, I did not understand what it is with the tracing of the recursion. I have some file with this content: ---------------------- (defun foo (n) (print n) (when (plusp n) (foo (1- n)))) (defun bbb () (print "bbb")) (defun aaa () (print "aaa") (bbb)) ---------------------- Then I compile it with C-c C-k and switch to REPL with C-c C-z, then all happens this way out: CL-USER> (trace foo aaa bbb) (BBB AAA FOO) CL-USER> (foo 10) 0[7]: (FOO 10) 10 9 8 7 6 5 4 3 2 1 0 0[7]: returned NIL NIL CL-USER> (aaa) 0[7]: (AAA) "aaa" 1[7]: (BBB) "bbb" 1[7]: returned "bbb" 0[7]: returned "bbb" "bbb" CL-USER> (defun bar (n) (print n) (when (plusp n) (bar (1- n)))) BAR CL-USER> (trace bar) (BAR) CL-USER> (bar 3) 0[7]: (BAR 3) 3 1[7]: (BAR 2) 2 2[7]: (BAR 1) 1 3[7]: (BAR 0) 0 3[7]: returned NIL 2[7]: returned NIL 1[7]: returned NIL 0[7]: returned NIL NIL CL-USER> Why it traces only the first call to FOO when it is compiled outside the REPL? If I need to recompile the code with "tracing of the FOO enabled", then how can I do this? Your help will be appreciated.
From: Piotr Chamera on 20 Apr 2010 17:12 Aleksandr Vinokurov pisze: > Hello all, > > I did not understand what it is with the tracing of the recursion. I > have some file with this content: > > (...) > > Why it traces only the first call to FOO when it is compiled outside > the REPL? If I need to recompile the code with "tracing of the FOO > enabled", then how can I do this? Because compiler made optimisation of tail recursion into iteration? You can try (declare (optimize (speed X) (safety Y) (debug Z))) in your function with X, Y and Z you can find in documentation of your CommonLisp implementation (probably Z = 3).
From: Aleksandr Vinokurov on 21 Apr 2010 02:49 Piotr Chamera <piotr_chamera(a)poczta.onet.pl> writes: > Aleksandr Vinokurov pisze: >> Hello all, >> >> I did not understand what it is with the tracing of the recursion. I >> have some file with this content: >> >> (...) >> >> Why it traces only the first call to FOO when it is compiled outside >> the REPL? If I need to recompile the code with "tracing of the FOO >> enabled", then how can I do this? > > Because compiler made optimisation of tail recursion into iteration? > > You can try > > (declare (optimize (speed X) (safety Y) (debug Z))) > > in your function with X, Y and Z you can find in documentation > of your CommonLisp implementation (probably Z = 3). Yes, I've suggested that and have already tried to optimize for debug 3, but it was speed 0 which was the case. Thank you, Piotr.
From: Alan Malloy on 21 Apr 2010 05:44 Aleksandr Vinokurov wrote: > Hello all, > > I did not understand what it is with the tracing of the recursion. I > have some file with this content: > > ---------------------- > (defun foo (n) > (print n) > (when (plusp n) (foo (1- n)))) > > (defun bbb () > (print "bbb")) > > (defun aaa () > (print "aaa") > (bbb)) > ---------------------- > > Then I compile it with C-c C-k and switch to REPL with C-c C-z, then > all happens this way out: > > CL-USER> (trace foo aaa bbb) > (BBB AAA FOO) > CL-USER> (foo 10) > 0[7]: (FOO 10) > > 10 > 9 > 8 > 7 > 6 > 5 > 4 > 3 > 2 > 1 > 0 > 0[7]: returned NIL > NIL > CL-USER> (aaa) > 0[7]: (AAA) > > "aaa" > 1[7]: (BBB) > > "bbb" > 1[7]: returned "bbb" > 0[7]: returned "bbb" > "bbb" > CL-USER> (defun bar (n) (print n) (when (plusp n) (bar (1- n)))) > BAR > CL-USER> (trace bar) > (BAR) > CL-USER> (bar 3) > 0[7]: (BAR 3) > > 3 > 1[7]: (BAR 2) > > 2 > 2[7]: (BAR 1) > > 1 > 3[7]: (BAR 0) > > 0 > 3[7]: returned NIL > 2[7]: returned NIL > 1[7]: returned NIL > 0[7]: returned NIL > NIL > CL-USER> > > > Why it traces only the first call to FOO when it is compiled outside > the REPL? If I need to recompile the code with "tracing of the FOO > enabled", then how can I do this? > > Your help will be appreciated. The other option is to, rather than compile with C-c C-k, evaluate with C-c C-c. This causes the function to be interpreted rather than compiled, which fixes the trace behavior. -- Cheers, Alan (San Jose, California, USA)
|
Pages: 1 Prev: Iterate: nested maximization returning two values Next: Reason to hate loop |