From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: srfi-1 list-copy improper lists Date: Wed, 13 Aug 2003 10:23:12 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <871xvq1k3z.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1060734294 31674 80.91.224.253 (13 Aug 2003 00:24:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 13 Aug 2003 00:24:54 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Aug 13 02:24:53 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19mjRd-0001gO-00 for ; Wed, 13 Aug 2003 02:24:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19mjQv-0003LO-Rm for guile-devel@m.gmane.org; Tue, 12 Aug 2003 20:24:09 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19mjQq-0003IJ-GB for guile-devel@gnu.org; Tue, 12 Aug 2003 20:24:04 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19mjQK-0002aA-32 for guile-devel@gnu.org; Tue, 12 Aug 2003 20:24:03 -0400 Original-Received: from [61.8.0.36] (helo=snoopy.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.20) id 19mjQJ-0002Xw-6a for guile-devel@gnu.org; Tue, 12 Aug 2003 20:23:31 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) by snoopy.pacific.net.au (8.12.3/8.12.3/Debian-6.4) with ESMTP id h7D0NT0J012220 for ; Wed, 13 Aug 2003 10:23:29 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h7D0NTkv028651 for ; Wed, 13 Aug 2003 10:23:29 +1000 (EST) Original-Received: from localhost (ppp123.dyn228.pacific.net.au [203.143.228.123]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h7D0NNos007288 for ; Wed, 13 Aug 2003 10:23:26 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19mjQ2-0006fq-00; Wed, 13 Aug 2003 10:23:14 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2693 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2693 --=-=-= A little spot of code for an item from the todo list, * srfi-1.c, srfi-1.h, srfi-1.scm (list-copy): New function, derived from core list-copy but allowing improper lists, per SRFI-1 spec. * tests/srfi-1.test (list-copy): New tests. I think this should go in the 1.6 branch too. I suppose it'd be easier to relax the core list-copy, but for now at least a version in the srfi-1 module can do what srfi-1 says it should. --=-=-= Content-Disposition: attachment; filename=srfi-1.c.list-copy.diff --- srfi-1.c.~1.10.~ 2003-07-29 09:50:41.000000000 +1000 +++ srfi-1.c 2003-08-11 12:06:49.000000000 +1000 @@ -382,6 +382,39 @@ #undef FUNC_NAME +/* This routine differs from the core list-copy in allowing improper lists. + Maybe the core could allow them similarly, but for now this code exists + to satisfy the SRFI-1 spec. */ + +SCM_DEFINE (scm_srfi1_list_copy, "list-copy", 1, 0, 0, + (SCM lst), + "Return a copy of the given list @var{lst}. @var{lst} can be a\n" + "proper or improper list. If @var{lst} is not a pair at all\n" + "then it's treated as the final tail of an improper list and\n" + "simply returned.") +#define FUNC_NAME s_scm_srfi1_list_copy +{ + SCM newlst; + SCM * fill_here; + SCM from_here; + + newlst = lst; + fill_here = &newlst; + from_here = lst; + + while (SCM_CONSP (from_here)) + { + SCM c; + c = scm_cons (SCM_CAR (from_here), SCM_CDR (from_here)); + *fill_here = c; + fill_here = SCM_CDRLOC (c); + from_here = SCM_CDR (from_here); + } + return newlst; +} +#undef FUNC_NAME + + /* Typechecking for multi-argument MAP and FOR-EACH. Verify that each element of the vector ARGV, except for the first, --=-=-= Content-Disposition: attachment; filename=srfi-1.scm.list-copy.diff --- srfi-1.scm.~1.28.~ 2003-07-29 09:51:02.000000000 +1000 +++ srfi-1.scm 2003-08-12 22:32:29.000000000 +1000 @@ -43,7 +43,7 @@ ;; cons* <= in the core ;; make-list <= in the core list-tabulate - ;; list-copy <= in the core + list-copy circular-list ;; iota ; Extended. @@ -207,14 +207,14 @@ ;; set-car! <= in the core ;; set-cdr! <= in the core ) - :re-export (cons list cons* make-list list-copy pair? null? + :re-export (cons list cons* make-list pair? null? car cdr caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr list-ref last-pair length append append! reverse reverse! filter filter! memq memv assq assv set-car! set-cdr!) - :replace (iota map for-each map-in-order list-index member + :replace (iota map for-each map-in-order list-copy list-index member delete delete! assoc) ) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--