From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marco Maggi Newsgroups: gmane.lisp.guile.user Subject: Re: Question on mutability of argument lists Date: Wed, 19 Mar 2014 18:01:31 +0100 Message-ID: <874n2unmvo.fsf@governatore.luna> References: Reply-To: marco.maggi-ipsu@poste.it NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: Quoted-Printable X-Trace: ger.gmane.org 1395249677 10406 80.91.229.3 (19 Mar 2014 17:21:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Mar 2014 17:21:17 +0000 (UTC) Cc: guile-user@gnu.org To: nisse@lysator.liu.se (Niels =?iso-8859-15?Q?M=F6ller?=) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Mar 19 18:21:25 2014 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WQKBA-0001hh-BO for guile-user@m.gmane.org; Wed, 19 Mar 2014 18:21:24 +0100 Original-Received: from localhost ([::1]:42860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQKB9-0000k0-Ng for guile-user@m.gmane.org; Wed, 19 Mar 2014 13:21:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQKAu-0000YU-10 for guile-user@gnu.org; Wed, 19 Mar 2014 13:21:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQKAm-0003ef-ND for guile-user@gnu.org; Wed, 19 Mar 2014 13:21:07 -0400 Original-Received: from relay-pt1.poste.it ([62.241.4.164]:58253) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQKAm-0003eT-G8 for guile-user@gnu.org; Wed, 19 Mar 2014 13:21:00 -0400 Original-Received: from governatore.luna (93.144.46.190) by relay-pt1.poste.it (8.5.142) (authenticated as marco.maggi-ipsu@poste.it) id 5328DE470004A0C1; Wed, 19 Mar 2014 18:00:19 +0100 Original-Sender: marco.maggi-ipsu@poste.it In-Reply-To: ("Niels =?iso-8859-15?Q?M=F6ller=22's?= message of "Wed, 19 Mar 2014 10:34:43 +0100") Original-Lines: 53 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 62.241.4.164 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:11135 Archived-At: Niels M=F6ller wrote: > When specifying the use of rest arguments for procedures > (r7rs, sec 4.1.4), it seems to imply that the passed > argument list is mutable? Yes, because it states "the sequence of actual arguments is converted into a newly allocated list, and the list is stored in a fresh location" and "The value stored in the binding of the last variable will be a newly allocated list" (PDF version, page 13, right column, description of formals); it is new at every function call, so we can do everything with it. > This is convenient in some ways, e.g., I think the > following definition of the list procedure should be > correct > (define (list . args) args) Yes. Vicare defines it as: (define list (lambda x x)) > However, for a natural implementation which evaluates > arguments and conses the results up to a list, this seems > to require an extra copy of the argument list, after all > values are evaluated and before the list is bound to the > rest parameter. Yes, but it depends on what is "natural" for you. In Vicare, when calling a Scheme function, all the arguments are pushed on the Scheme stack segment (similar to calling a C function) and then the function is called; the callee takes the leftover arguments and puts them into a newly allocated list. In this implementation there is no duplication of list's spine (with heap memory allocation), just use of stack slots. > To see why, assume that evaluation of one of the arguments > captures its continuation and returns several times. this > isn't the first argument evaluated, without the extra > copying, one gets several calls to the procedure with the > rest argument sharing structure, and if the shared part is > mutated, things go bad. Yes it would go that way. But the standard mandates that a new list must be built at every call and stored into a fresh location at every call; no shared structure is allowed. HTH --=20 "Now feel the funk blast!" Rage Against the Machine - "Calm like a bomb"