ron at flownet.com
Tue May 14 10:12:38 CDT 2013
This kind of question is better posed to a general Lisp newsgroup. This list is specific to CCL (f.k.a. OpenMCL).
But the answer is simple:
> pushing an element on the stack, (PUSH 1 X) is equivalent
> to (SETQ X (CONS 1 X)),
That is not true. Stacks and cons cells are fundamentally different data structures. You can build a stack out of cons cells, but you can't build cons cells out of a stack. A stack is *strictly* a last-in-first-out data structure, which is the reason it doesn't need to be garbage collected.
On May 14, 2013, at 3:37 AM, Taoufik Dachraoui wrote:
> This is probably simple but I could not figure out the explanation, I hope that
> someone could help me out
> CL-USER> (defun fac (n) (if (= n 0) 1 (* n (fac (- n 1)))))
> CL-USER> (time (fac 3))
> (FAC 3)
> took 0 milliseconds (0.000 seconds) to run.
> During that period, and with 1 available CPU core,
> 0 milliseconds (0.000 seconds) were spent in user mode
> 0 milliseconds (0.000 seconds) were spent in system mode
> As you can see, there is no consing when FAC is called
> Now, knowing that pushing an element on the stack, (PUSH 1 X) is equivalent
> to (SETQ X (CONS 1 X)), and since FAC is using a stack and thus pushing
> values on the stack why there is no consing when (FAC 3) is called?
> I believe there is a simple explanation but I could not figure it out
> Kind regards
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
More information about the Openmcl-devel