unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [VM] Tail recursion and multiple values
@ 2009-02-28 14:27 Ludovic Courtès
  2009-02-28 14:45 ` Ludovic Courtès
  0 siblings, 1 reply; 11+ messages in thread
From: Ludovic Courtès @ 2009-02-28 14:27 UTC (permalink / raw)
  To: guile-devel

Hello!

Use of multiple values breaks tail recursion in VM-compiled code:

  (let loop ((x 1000000))
    (and (> x 0)
         (call-with-values
             (lambda ()
               (values (1+ x) (1- x)))
           (lambda (next prev)
             (loop prev)))))

This example yields a stack overflow with the VM, whereas tail recursion
is correctly handled by the interpreter.  Tail recursion for
`call-with-values' is mandated by R5RS (info "(r5rs)Proper tail
recursion"):

  Certain built-in procedures are also required to perform tail calls.
  The first argument passed to `apply' and to
  `call-with-current-continuation', and the second argument passed to
  `call-with-values', must be called via a tail call.  Similarly, `eval'
  must evaluate its argument as if it were in tail position within the
  `eval' procedure.

I'll look into it and report back if no one beats me.  ;-)

Thanks,
Ludo'.





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-03-04 22:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-28 14:27 [VM] Tail recursion and multiple values Ludovic Courtès
2009-02-28 14:45 ` Ludovic Courtès
2009-03-01 20:31   ` Andy Wingo
2009-03-01 23:48     ` Ludovic Courtès
2009-03-02 18:03       ` Andy Wingo
2009-03-02 21:55         ` Ludovic Courtès
2009-03-02 23:15           ` Andy Wingo
2009-03-02 23:33             ` Andreas Rottmann
2009-03-02 23:43             ` Eduardo Cavazos
2009-03-03 23:45             ` Ludovic Courtès
2009-03-04 22:11               ` Clinton Ebadi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).