guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is apply procedure not tail recursive?


From: Noah Lavine
Subject: Re: Is apply procedure not tail recursive?
Date: Wed, 16 Jan 2013 19:20:13 -0500

Hello,

This is just a guess, but I think that apply is trying to put all of the elements of the argument list on the stack before calling +. Presumably when it calls +, those will all be consed up into another list, but it's not taking a shortcut there. So yes, it is tail recursive, but I think you've hit a different issue.

Noah Lavine


On Wed, Jan 16, 2013 at 6:34 PM, Akop Pogosian <address@hidden> wrote:
(define (zeros n)
;; Make list of n zeros
  (define (zeros-iter n lst)
    (if (= n 0)
        lst
        (zeros-iter (- n 1)
                         (cons 0 lst))))
  (zeros-iter n '()))

Results:

guile> (apply + (zeros (expt 10 3)))
$2 = 0
guile> (apply + (zeros (expt 10 4)))
$3 = 0
guile> (apply + (zeros (expt 10 5)))
ERROR: Throw to key `vm-error' with args `(vm-run "VM: Stack overflow" ())'.
guile> (apply + (zeros (expt 10 6)))

Process scheme aborted (core dumped)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]