[Top][All Lists]

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

Re: Is apply procedure not tail recursive?

From: David Thompson
Subject: Re: Is apply procedure not tail recursive?
Date: Wed, 16 Jan 2013 19:56:18 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130109 Thunderbird/17.0.2

On 01/16/2013 06:34 PM, Akop Pogosian wrote:
(define (zeros n)
;; Make list of n zeros
   (define (zeros-iter n lst)
     (if (= n 0)
         (zeros-iter (- n 1)
                          (cons 0 lst))))
   (zeros-iter n '()))


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)

Using a procedure such as reduce should make this work. apply isn't meant for this sort of task.

reply via email to

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