[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[VM] Tail recursion and multiple values
From: |
Ludovic Courtès |
Subject: |
[VM] Tail recursion and multiple values |
Date: |
Sat, 28 Feb 2009 15:27:09 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.90 (gnu/linux) |
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'.
- [VM] Tail recursion and multiple values,
Ludovic Courtès <=