unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* srfi-1 map!
@ 2003-11-11  0:32 Kevin Ryde
  2003-11-11 14:58 ` a circular dilemma . #0# (was Re: srfi-1 map!) Stephen Compall
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Ryde @ 2003-11-11  0:32 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 194 bytes --]

I've been finding it a bit annoying that map can handle long lists but
map! can't.

        * srfi-1.scm (map!): Define as an alias for map, previous definition
        was not tail-recursive.


[-- Attachment #2: srfi-1.scm.mapx.diff --]
[-- Type: text/plain, Size: 702 bytes --]

--- srfi-1.scm.~1.29.~	1970-01-01 10:00:01.000000000 +1000
+++ srfi-1.scm	2003-11-11 10:28:35.000000000 +1000
@@ -572,22 +572,8 @@
 	'()
 	(append! (apply f (map1 car l)) (lp (map1 cdr l)))))))
 
-(define (map! f list1 . rest)
-  (if (null? rest)
-    (let lp ((l list1))
-      (if (null? l)
-	'()
-	(begin
-	  (set-car! l (f (car l)))
-	  (set-cdr! l (lp (cdr l)))
-	  l)))
-    (let lp ((l (cons list1 rest)) (res list1))
-      (if (any1 null? l)
-	'()
-	(begin
-	  (set-car! res (apply f (map1 car l)))
-	  (set-cdr! res (lp (map1 cdr l) (cdr res)))
-	  res)))))
+;; OPTIMIZE-ME: Re-use cons cells of given list(s)
+(define map! map)
 
 (define (pair-for-each f clist1 . rest)
   (if (null? rest)

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-11-18 22:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-11  0:32 srfi-1 map! Kevin Ryde
2003-11-11 14:58 ` a circular dilemma . #0# (was Re: srfi-1 map!) Stephen Compall
2003-11-14 19:28   ` Kevin Ryde
2003-11-17 20:21     ` Stephen Compall
2003-11-18 22:57       ` Kevin Ryde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).