bugGuile - Bugs: bug #30071, unfold isn't tail-recursive

 
 

bug #30071: unfold isn't tail-recursive

Submitter:  Szavai Gyula <szgyg>
Submitted:  Mon 07 Jun 2010 06:30:34 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  civodul
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 08 Oct 2010 02:28:05 PM UTC, comment #3: 
Ludovic Courtès <civodul>
Group administrator
Thu 10 Jun 2010 03:57:38 PM UTC, comment #2: 

; I mean the simple implementation

(define* (unfold p f g s #:optional (t (lambda (x) '())))
  (let loop ((s s) (a '()))
    (if (p s)
        (rev-append a (t s))
      (loop (g s) (cons (f s) a)))))

(define (rev-append xs ys)
  (if (null? xs)
      ys
    (rev-append (cdr xs) (cons (car xs) ys))))

Szavai Gyula <szgyg>
Tue 08 Jun 2010 09:47:56 PM UTC, comment #1: 

Hello,

Doesn't the TAIL-GEN argument prevent it from being implemented in a tail-recursive fashion?

(When TAIL-GEN is omitted it can be tail-recursive.)

Thanks,
Ludo'.

Ludovic Courtès <civodul>
Group administrator
Mon 07 Jun 2010 06:30:34 PM UTC, original submission:  

(use-modules (srfi srfi-1))

(write
 (false-if-exception
  (let ((stack (* 0.05 (cadr (member 'stack (debug-options))))))
    (unfold (lambda (x) (> x stack)) identity 1+ 0)
    #t)))

Szavai Gyula <szgyg>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by civodul (Posted a comment)
  • -email is unavailable- added by szgyg (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-10-08 civodul StatusNone Fixed
        Open/ClosedOpen Closed
    2010-06-17 civodul Assigned toNone civodul

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code