[Openmcl-devel] consing

Tom Emerson tremerson at gmail.com
Tue May 14 16:01:27 UTC 2013


If you disassemble your fact function you'll see that there is no consing
going on: the machine stack is being used directly. I'm not sure why you
would expect the compiler to use conses for this.



On Tue, May 14, 2013 at 11:52 AM, Taoufik Dachraoui <
dachraoui.taoufik at gmail.com> wrote:

> What is not true? I am not saying that stacks are conses; we can push and
> pop elements from a stack and macroexpanding (PUSH 1 X) gives (SETQ X (CONS
> 1 X)); so the stack, used by pop/push, in CCL is implemented
> using conses; we can implement stacks using arrays (no consing) if we wish
> so.
>
> Now, the reason I am asking, is that I am implementing an interpreter for
> a small language and I am using 3 stacks with a lot of consing. I wanted to
> find a solution so that I can avoid consing; I recalled when we call a
> function the passed parameters are pushed into a stack (implemented with
> registers ESP/EBP), I am wondering if I can find a way to use the
> processor's stack as for function calls to avoid consing.
>
> Or, how do you implement a VM using CCL for a new language? (any thing
> offered by CCL even if it is not
> standard would be acceptable).
>
> Taoufik
>
>
>
> On Tue, May 14, 2013 at 5:12 PM, Ron Garret <ron at flownet.com> wrote:
>
>> 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.
>>
>> rg
>>
>> On May 14, 2013, at 3:37 AM, Taoufik Dachraoui wrote:
>>
>> > Hi
>> >
>> > 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)))))
>> > FAC
>> > 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
>> > 6
>> >
>> > 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
>> > Taoufik
>> >
>> > _______________________________________________
>> > Openmcl-devel mailing list
>> > Openmcl-devel at clozure.com
>> > http://clozure.com/mailman/listinfo/openmcl-devel
>>
>>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>


-- 
Tom Emerson
tremerson at gmail.com
http://www.dreamersrealm.net/tree
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clozure.com/pipermail/openmcl-devel/attachments/20130514/a741c56d/attachment.html>


More information about the Openmcl-devel mailing list