[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Tracing tail recursive fns in ccl

Jeff Shrager

5/7/2015 9:33:00 PM

Okay, so ccl automatically compiles tail recursions. Fine for execution, but it makes it hard for me to debug, and esp. to demo to students bcs tracing these fns doesn't show you anything. There appears to be something that can be done to stop it, but it's nearly incomprehensible (to me, anyway):

http://trac.clozure.com/ccl/wiki/Decla...

esp. w/o any examples.

Can someone give me the expr that will turn tail recursion compilation OFF in a ccl listener, so that thereafter trace, etc. will work?

Thanks in advance!
4 Answers

Pascal J. Bourguignon

5/7/2015 9:40:00 PM

0

jshrager@gmail.com writes:

> Okay, so ccl automatically compiles tail recursions. Fine for
> execution, but it makes it hard for me to debug, and esp. to demo to
> students bcs tracing these fns doesn't show you anything. There
> appears to be something that can be done to stop it, but it's nearly
> incomprehensible (to me, anyway):
>
> http://trac.clozure.com/ccl/wiki/Decla...
>
> esp. w/o any examples.
>
> Can someone give me the expr that will turn tail recursion compilation
> OFF in a ccl listener, so that thereafter trace, etc. will work?
>
> Thanks in advance!

cl-user> (declaim (optimize (space 0) (speed 0) (debug 3) (safety 3)))
nil
cl-user> (defun f (x) (if (zerop x) 1 (* x (f (1- x)))))
f
cl-user> (trace f)
nil
cl-user> (f 4)
0> Calling (f 4)
1> Calling (f 3)
2> Calling (f 2)
3> Calling (f 1)
4> Calling (f 0)
<4 f returned 1
<3 f returned 1
<2 f returned 2
<1 f returned 6
<0 f returned 24
24
cl-user>
--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

William James

5/8/2015 2:38:00 AM

0

Pascal J. Bourguignon wrote:

> cl-user> (defun f (x) (if (zerop x) 1 (* x (f (1- x)))))

That's not tail-recursive.

--
In Sweden, the leadership seems to show Europe's most extensive cultural
self-denial, or rather -- a deeply felt self loathing, which many feel is the
perfect recipe for driving a peaceful nation to destruction.
fjordman.blogspot.ca/2005/05/is-swedish-democracy-collapsing.html

Jeff Shrager

5/8/2015 4:56:00 PM

0

No, it's not, but ccl has the same problem with this, and his 'fix' works.

Thanks!

Pascal J. Bourguignon

5/8/2015 5:15:00 PM

0

"WJ" <w_a_x_man@yahoo.com> writes:

> Pascal J. Bourguignon wrote:
>
>> cl-user> (defun f (x) (if (zerop x) 1 (* x (f (1- x)))))
>
> That's not tail-recursive.

Oops, sorry.

cl-user> (defun f (x &optional (f 1)) (if (zerop x) f (f (1- x) (* x f))))
f
cl-user> (trace f)
nil
cl-user> (f 4)
0> Calling (f 4)
1> Calling (f 3 4)
2> Calling (f 2 12)
3> Calling (f 1 24)
4> Calling (f 0 24)
<4 f returned 24
<3 f returned 24
<2 f returned 24
<1 f returned 24
<0 f returned 24
24
cl-user>


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk