From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: philip@warpmail.net (Philip K.) Newsgroups: gmane.lisp.guile.user Subject: Weird Guile Scheme Behaviour Date: Fri, 13 Sep 2019 11:43:06 +0200 Message-ID: <87pnk4v8et.fsf@bulbul> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="267678"; mail-complaints-to="usenet@blaine.gmane.org" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Sep 13 14:39:09 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 1i8kqx-0017Sv-CU for guile-user@m.gmane.org; Fri, 13 Sep 2019 14:39:08 +0200 Original-Received: from localhost ([::1]:43342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8kqw-0005cl-9d for guile-user@m.gmane.org; Fri, 13 Sep 2019 08:39:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56565) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8i6j-0003yK-Nd for guile-user@gnu.org; Fri, 13 Sep 2019 05:43:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8i6i-0000qW-Jf for guile-user@gnu.org; Fri, 13 Sep 2019 05:43:13 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:33005) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8i6i-0000oI-Am for guile-user@gnu.org; Fri, 13 Sep 2019 05:43:12 -0400 Original-Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 685E021ACF for ; Fri, 13 Sep 2019 05:43:10 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 13 Sep 2019 05:43:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=warpmail.net; h= from:to:subject:date:message-id:mime-version:content-type; s= fm1; bh=Jkw61HEvN7YwnxjX61AsZClrvQI1Yl0Rkqj7hJW9mao=; b=llNuJGUg AQUdrO1cdUvW+ZNRdLbeDifLbcrH8/3z+Fa2emDmUYvigOX4eQRIcb/FdD6phtU9 sx0fB2HTTCaGMD2VAy60dIhMJ8hn0HgBM1pBTxQaPlFijK874ny8yf00UFh0nk/O Mt/jYqTRzf+/HK4GZ8RpTfO7GE6/nL5BBlAfCmDokn0FO3iWCUV5iAf2vd2J4znC 9TDx1k0QhHx2qOP83FyxqrdC+CE6GYRmj4B5FFzZ9hthouAshQZStnhXt/UwFtxj rJ7XwpE3LsVpisrcU8xMYlzPhYkmasUeBN0Zjh4C+mrfvqh9Cu0mUd19I2qjBRr3 o2iw28RiI4n3Fg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=Jkw61HEvN7YwnxjX61AsZClrvQI1Y l0Rkqj7hJW9mao=; b=qZ2tPCEJd8f1GhDqsgjLxihBYTIPtmv3INXeK06rMMYGV UO9aqiGWMeHxkTRyPtNeuiHIHi27J95rdho5Elx0jrK2C+YaPYVRGCE8TyJPfga2 Mh8wLpvTaNdb9m6+5ZBs0vK9rT2BPknKJgouZ9qfHQ+Od8bTOt4LZnk0Bfq7y/fv fuFG1MbXKMEdMAo6U5O5sEX+VQnhFvLzUWQkiCW2NntL8qgPhdn8k3478bYLwM13 iaDYN8iROoLEgF/b/aRD0GrYm5T2jERItqmiyze4s5bmn29XMhYoQHStW+Yg2HXo Tj1qk96b7gpQkn9T9oWX2zyCKVqTfyl7iNSFQMngA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrtdejgddukecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkfggtgesghdtreertddttd enucfhrhhomhepphhhihhlihhpseifrghrphhmrghilhdrnhgvthculdfrhhhilhhiphcu mfdrmdenucffohhmrghinheplhgrihhntghhrghnrdhorhhgnecukfhppeejledrvddule drudelhedrvdegtdenucfrrghrrghmpehmrghilhhfrhhomhepphhhihhlihhpseifrghr phhmrghilhdrnhgvthenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Original-Received: from localhost (p4fdbc3f0.dip0.t-ipconnect.de [79.219.195.240]) by mail.messagingengine.com (Postfix) with ESMTPA id CB9028005A for ; Fri, 13 Sep 2019 05:43:09 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.25 X-Mailman-Approved-At: Fri, 13 Sep 2019 08:38:40 -0400 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:15724 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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) =2D-=20 With kind regards, Philip K. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEXEVvqaSeWykH0GvsTLppj2Aa7OEFAl17ZKoACgkQTLppj2Aa 7OHEAgf+MieEeONPVnDDbEm32WQRbaBVCpoCQ2eL4UYifwPwd8EEiPgN4IkBgf5M ZJkVQs1kB34FyzzGbN9wIAYONhFQq+2Ds70ZqMJx3OZzs3a65jozcm8ZFJjgPv6y 9sMZEtfU1cRgvBYNsZstEM1bpXF++RPSq9Osm9xF8D6Qu9BMiOq+2Poq4zQLHVaZ v031dYIerpEZSCyoinZzlOFDA2o9Pmy44tktP5v2+bDF5Ankkp0lqVSpOM92Jkn2 W/Q+EK95upzAuFKb/zUcFE5QBQC6PFoKZWMeckwS8Hj2guZkzx724x3VXvng2UMb W3bguKD5prs9f2P/fTp9s7gFphA39g== =puqG -----END PGP SIGNATURE----- --=-=-=--