From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] New function array-mutable? Date: Thu, 09 Dec 2021 20:34:00 +0000 Message-ID: References: <32F75DE0-14DA-4B7F-B6A9-81462A847A30@sarc.name> <97DC61EC-3DD4-444B-98DB-AB9A823EA1F3@sarc.name> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29515"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.38.3-1 Cc: guile-devel@gnu.org To: lloda Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Dec 09 21:34:45 2021 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mvQ7o-0007Ve-7v for guile-devel@m.gmane-mx.org; Thu, 09 Dec 2021 21:34:44 +0100 Original-Received: from localhost ([::1]:35408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvQ7n-0008O1-7z for guile-devel@m.gmane-mx.org; Thu, 09 Dec 2021 15:34:43 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvQ7P-0008MT-LB for guile-devel@gnu.org; Thu, 09 Dec 2021 15:34:19 -0500 Original-Received: from [2a02:1800:120:4::f00:14] (port=40554 helo=xavier.telenet-ops.be) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mvQ7G-0007Dy-6T for guile-devel@gnu.org; Thu, 09 Dec 2021 15:34:19 -0500 Original-Received: from ptr-bvsjgyhxw7psv60dyze.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by xavier.telenet-ops.be with bizsmtp id ULa02600t4UW6Th01La1k0; Thu, 09 Dec 2021 21:34:01 +0100 In-Reply-To: <97DC61EC-3DD4-444B-98DB-AB9A823EA1F3@sarc.name> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1639082041; bh=66j7t+YKYTa8Fx1RHzIihTv0p6GVMs+3OasVmumWPAw=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=BugL0o+X2Mgu0lo32blw5QwCx6fxdG+YtSJOHI5LO/xshyUTJoWQrYESwSpRcXytk GSCGwmeAzUDf1eqhfukVqEMPu+kSt/Y0SbM32ZyArbb0RMeTjLtiAkhKRddEY3KJAT T9K8ivW4fh5WhrMUmtHycb+yMHHCX2yvP1qjpIJTOIDzj+TGOdwgvYvuQBEcgX7THY Cf4PD53gGVUjvYW2Xp5XHvwkMUolv36lbeZf7VBv6d/vtkdMID6K/NnRtJbgKDf9m6 xM4G1+V5GB2+hd97OSieuYu0Mq41lFPRcxRNNEkJU9p6qBtMFfi9czIFG4Rs84dezO HTCNyHygitQUQ== X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a02:1800:120:4::f00:14 (failed) Received-SPF: pass client-ip=2a02:1800:120:4::f00:14; envelope-from=maximedevos@telenet.be; helo=xavier.telenet-ops.be X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20992 Archived-At: Hi, lloda schreef op do 25-11-2021 om 20:08 [+0100]: I think literal arrays are always immutable, and one could base the test on that. > Is such a function useful in some other context? If one has an array which is already immutable, it can be referenced freely and copying it seems unnecessary. If one has a mutable array, is there any reason why one would want to make an immutable copy? To avoid accidental mutation (though at the cost of making a copy). Also, literals aren't necessarily immutable if 'eval' is used: (let ((literal (make-array 0 1 1))) (eval `(array-set! ',literal #xff 0 0) (current-module)) literal) ;; output: #2((255)) As-is, this is a somewhat contrived example. But 'eval' is useful REPL-like things, and if someone implements a REPL-like thing, they might want to ‘immutabilise’ all input first such that array-set! on literals will actually produce an exception as one would expect. An alternative method would be to compile the code before running (which is what the standard REPL does IIUC), but _requiring_ this extra step seems suboptimal to me. Greetings, Maxime. p.s. Somehow, your e-mail ended up in spam, for no apparent reason.