guile-devel
[Top][All Lists]
Advanced

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

srfi-1 circular-list


From: Kevin Ryde
Subject: srfi-1 circular-list
Date: Sat, 20 Mar 2004 08:11:27 +1000
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux)

        * srfi-1.scm (circular-list): Rewrite using set-cdr!, no need to copy
        parameter list.

--- srfi-1.scm.~1.31.~  2003-12-03 07:14:46.000000000 +1000
+++ srfi-1.scm  2004-03-18 14:59:56.000000000 +1000
@@ -1,6 +1,6 @@
 ;;; srfi-1.scm --- List Library
 
-;;     Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+;;     Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 ;;
 ;; This library is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU Lesser General Public
@@ -247,16 +247,10 @@
       acc
       (lp (- n 1) (cons (init-proc (- n 1)) acc)))))
 
-(define (circular-list elt1 . rest)
-  (let ((start (cons elt1 '())))
-    (let lp ((r rest) (p start))
-      (if (null? r)
-       (begin
-         (set-cdr! p start)
-         start)
-       (begin
-         (set-cdr! p (cons (car r) '()))
-         (lp (cdr r) (cdr p)))))))
+(define (circular-list . lst)
+  (if (not (null? lst))
+      (set-cdr! (last-pair lst) lst))
+  lst)
 
 (define (iota count . rest)
   (check-arg-type non-negative-integer? count "iota")

reply via email to

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