From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: Weird Guile Scheme Behaviour Date: Fri, 13 Sep 2019 13:43:40 +0100 Message-ID: References: <87pnk4v8et.fsf@bulbul> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="18385"; mail-complaints-to="usenet@blaine.gmane.org" Cc: guile-user@gnu.org To: "Philip K." Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Sep 13 14:44:24 2019 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i8kw3-0004fY-QO for guile-user@m.gmane.org; Fri, 13 Sep 2019 14:44:23 +0200 Original-Received: from localhost ([::1]:43388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8kw2-0007F8-Gk for guile-user@m.gmane.org; Fri, 13 Sep 2019 08:44:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56636) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8kva-0007DG-8R for guile-user@gnu.org; Fri, 13 Sep 2019 08:43:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8kvY-0001B4-M6 for guile-user@gnu.org; Fri, 13 Sep 2019 08:43:54 -0400 Original-Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]:37531) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i8kvY-0001Al-Hr for guile-user@gnu.org; Fri, 13 Sep 2019 08:43:52 -0400 Original-Received: by mail-qt1-x82e.google.com with SMTP id g13so33281923qtj.4 for ; Fri, 13 Sep 2019 05:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=x9NRwzGV26DXrRp7vCDNQesFl02MX5jupi1SDLsBNAo=; b=jNAhXA9RQDihjbGRDyd/3vlkVGBzQ/AhXuvwbik+KxpyZhqkMszVGoPAXpPXSX1pfE wrhqmweuEZYNu/Fy65Xv1mpULTtx7tl7o+sCZKBtHdPuhaSYCszxagT/C0JR2cjFzIcm UI+sVg1zzATfIThlQ3h/auK5pjo+f5EVjPn5cMw7tDXOimGdKYYx58g45ckw36V3U7kD s3E5JrZpTnshr7D50NB1mDSftsYW7jyhsKVr++FtAVmWRquJthQELIZD0sjlRs5JZTGz hjH8eAjBb7+O2O3lIEPGUkzoPqqHWF7aLVFIKtH3cveIfztaPuDdV9VdRB35RnksY/nt VncA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=x9NRwzGV26DXrRp7vCDNQesFl02MX5jupi1SDLsBNAo=; b=bynI7YpeHyZ/e/uyyJrYE3/TeAT5HfS7W8KMufIFwyK+XQdWStyItb68WcVkn9OhtG Vy6JVjtbKcY+c2eOrzCUo//zabJDjUHMePSbOtZqtpS01YB6VkIno7wsWvMeJ4dIbJLq v7+TQ6RIY6p5MIIBPm4wnzsIxf0APVhZ44a7JyGPVj/zcCMxLT9R47/MuFUpWFQF6tJd GuimEsqEpsljDMJV6j4uXi+UHHVM6tvyfKtfMAwWMN9XjK82yqVNGUy1Z7+kHTfHBpWz Q7mHPjnoMciv7lOvcPGv26q9aBYRcP/kg+c+DPMIBMJPPbDNBPG6YXTmA1N9ZNhyyCvk OGyQ== X-Gm-Message-State: APjAAAW1ha98B+aECkQpJe3UwYiCPb/XwL1MH3YCXkR8xMOzWErzhCo1 6pZXd9MptXCu3y5VYxm0rBuhbUp+ud8dWsAaDDY= X-Google-Smtp-Source: APXvYqz8itaC8n2Pluh3jbGbLXtvXL7KMSSX0bk9NyMGZ8zVG1ajCxGaNbBxfEcATd77N7S4895956s66blbGmJcA+g= X-Received: by 2002:ac8:45d2:: with SMTP id e18mr2527454qto.321.1568378631615; Fri, 13 Sep 2019 05:43:51 -0700 (PDT) In-Reply-To: <87pnk4v8et.fsf@bulbul> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82e X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.org gmane.lisp.guile.user:15725 Archived-At: Correct usage of append! usually requires (set! x (append! x ....)), despite what you might think from the !. I haven't read the rest of your email carefully, but I wonder if that will make a difference? Best wishes, Neil On Fri, 13 Sep 2019 at 13:39, Philip K. wrote: > > Hi, > > I was reading a thread on an imageboard[0] the other day, then I came > across a most peculiar "bug", if it even is one. Since the original > example was a bit dense (it tried to solve a problem someone else had > posted, that's not relevant here), I tried to construct a minimal > working example to discuss here. > > Compare > > (define (reverse-iota-1 max) > (let ((numbers '(start))) > (let loop ((val 0)) > (append! numbers > (if (< max val) > '() > (begin > (loop (1+ val)) > (list val))))) > numbers)) > > and > > (define (reverse-iota-2 max) > (let ((numbers '(start))) > (let loop ((val 0)) > (append! numbers > (if (< max val) > '() > (begin > (loop (1+ val)) > (list val))))) > (cdr numbers))) > > (I know, the style is horrible, but that's not the point. Also, both > have an internal state, so you have to re-eval the function every time > before starting the function itself.) > > The only difference is in the last line. The first function returns the > entire list (with the start symbol), and the second tries to chop it > off. > > But what happens is that (reverse-iota-1 4) evals to '(start 3 2 1 0) > while (reverse-iota-2 4) just returns '()! > > This seems weird, since my intuition, and that of the poster above, was > that all that should change in reverse-iota-2 is that the "start" symbol > should fall away. > > It's obvious that this has something to do with the destructive > "append!", but I'm not quite sure what leads to this unexpected result. > Is it maybe a optimisation error? Any opinions? > > [0]: https://lainchan.org/%CE%BB/res/12185.html#15066 (SFW) > > -- > With kind regards, > Philip K. >