unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: srfi-1 map!
Date: Tue, 11 Nov 2003 10:32:52 +1000	[thread overview]
Message-ID: <87ptfzpwwb.fsf@zip.com.au> (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

             reply	other threads:[~2003-11-11  0:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-11  0:32 Kevin Ryde [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ptfzpwwb.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).