[gambit-list] Is stack frame allocation optimized in this following case?

Mikael mikael.rcv at gmail.com
Thu Jan 9 17:30:59 EST 2014


Dear Marc,

Is there any optimization in Gambit that zaps stack frame allocation when
not necessary?

What I'm looking for is that sometimes it's convenient to write code in the
format of (1)
below.

However, as everyone can see, that format implies the allocation of a stack
frame on entry
into the loop, because the loop not is executed in the tail position.

A way to work around that could be to write the code in the format of (2)
instead.
The |at| variable will be GC:ed as soon as it's not referenced anyhow by
Gambit thanks to
the dead variables optimization.

So what I'm looking to understand now is that, if it would be more concise
to implement a
problem in the format of (1), then is that also equally performant in every
way as expressing the same problem in the format of (2)?


; (1)
(begin
  [code to run before loop]

  (let loop ((at something))

    (if [not ready]
        [logic + invocation of loop]))

  [code to run after loop])


; (2)
(begin
  [code to run before loop]

  (let loop ((at something))

    (if [not ready]
        [logic + invocation of loop]

        [code to run after loop])))

Thanks,
Mikael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20140109/16b45c23/attachment.htm>


More information about the Gambit-list mailing list