From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: William ML Leslie Newsgroups: gmane.lisp.guile.devel Subject: Re: take! 0==1? Date: Fri, 12 Jul 2013 17:57:02 +1000 Message-ID: References: <87fvvkz1ui.fsf@nlvehvbe01nb29b.ddns.nl-htc01.nxp.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1373615831 4465 80.91.229.3 (12 Jul 2013 07:57:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Jul 2013 07:57:11 +0000 (UTC) Cc: guile-devel To: Jan Nieuwenhuizen Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jul 12 09:57:10 2013 Return-path: Envelope-to: guile-devel@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 1UxYE2-00067E-BC for guile-devel@m.gmane.org; Fri, 12 Jul 2013 09:57:10 +0200 Original-Received: from localhost ([::1]:47578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxYE2-0007Ay-2X for guile-devel@m.gmane.org; Fri, 12 Jul 2013 03:57:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxYDy-000777-7w for guile-devel@gnu.org; Fri, 12 Jul 2013 03:57:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UxYDv-0008Gb-AI for guile-devel@gnu.org; Fri, 12 Jul 2013 03:57:06 -0400 Original-Received: from mail-ob0-x22b.google.com ([2607:f8b0:4003:c01::22b]:58989) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxYDv-0008GH-6W; Fri, 12 Jul 2013 03:57:03 -0400 Original-Received: by mail-ob0-f171.google.com with SMTP id dn14so11069115obc.16 for ; Fri, 12 Jul 2013 00:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=M+BNkvGdLe858bySoSj7LgZFcqVsiJ9mi15759jSb+o=; b=0RrzlQNj4zTwDZ62yFiDynMLni++xzTDWO/L6GIm+OPVdy88fGObTKs6n0lkpXIVXs pR+QBDIUVpfHYNQ8O/xoEYIdrR4necPTThislj/cpjbWyJ1D11d2i013+L3BywbpR7C1 e67dkeQn/P2TlhOdGmD/5aGKnhSfI/0mmZboON+VCYmyDLtCyP7XdTU1t+cU+qlhlG8l 8MVN7Ku94IyxbIQCcmHF9juStZD165VSCMbczuhYKGAkwu90kyqFJR1N24ONAaD2N8Hb hvuLGmOuhzlegqSnu5ZLHPKkFdI3b3vTyvFlh3s5AGxb6Su90ScoUKlob1LjkVV2STck 3a3w== X-Received: by 10.60.35.40 with SMTP id e8mr35412099oej.34.1373615822403; Fri, 12 Jul 2013 00:57:02 -0700 (PDT) Original-Received: by 10.182.222.69 with HTTP; Fri, 12 Jul 2013 00:57:02 -0700 (PDT) In-Reply-To: <87fvvkz1ui.fsf@nlvehvbe01nb29b.ddns.nl-htc01.nxp.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::22b X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 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 Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16528 Archived-At: On 12 July 2013 17:14, Jan Nieuwenhuizen wrote: > Hi, > > Reading the documentation of take! > > -- Scheme Procedure: take lst i > -- Scheme Procedure: take! lst i > Return a list containing the first I elements of LST. > > `take!' may modify the structure of the argument list LST in order > to produce the result. > > its behaviour surpsises me. > > For list LST, (take! lst 0) leaves LST in the same state > as (take! lst 1) does. Worse, the return value suggests > that it worked Actually, I should clarify a few things, but this discussion probably belongs on guile-user. Whenever the documentation says 'may', it really means it. You absolutely cannot rely on the side-effecting behaviour, because an implementation that does no mutation whatsoever is a valid implementation of (take!), according to the documentation. All you're saying by using (take!) is, if it is more efficient to do so by altering the list, then please do. However, what it does is very simple to determine by looking at a box diagram for the following. scheme@(guile-user)> (use-modules (srfi srfi-1)) scheme@(guile-user)> (define xs '(a b c)) scheme@(guile-user)> (define ys (cdr xs)) scheme@(guile-user)> (define zs (cdr ys)) scheme@(guile-user)> (take! xs 3) ;; writes a nil at the end of the list, ie does nothing $3 = (a b c) scheme@(guile-user)> (take! xs 2) ;; replaces the reference to the last pair with nil $11 = (a b) scheme@(guile-user)> xs $12 = (a b) scheme@(guile-user)> ys $13 = (b) scheme@(guile-user)> zs ;; the last pair still exists, although it is not reachable from xs/ys $14 = (c) -- William Leslie Notice: Likely much of this email is, by the nature of copyright, covered under copyright law. You absolutely may reproduce any part of it in accordance with the copyright law of the nation you are reading this in. Any attempt to deny you those rights would be illegal without prior contractual agreement.