unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: lloda <lloda@sarc.name>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] New function array-mutable?
Date: Thu, 09 Dec 2021 20:34:00 +0000	[thread overview]
Message-ID: <e8dbdf613b701a958dab5ce3db06a25b7e01dff9.camel@telenet.be> (raw)
In-Reply-To: <97DC61EC-3DD4-444B-98DB-AB9A823EA1F3@sarc.name>

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.




  parent reply	other threads:[~2021-12-09 20:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-25 16:40 [PATCH] New function array-mutable? lloda
2021-11-25 18:19 ` Maxime Devos
2021-11-25 19:10   ` lloda
     [not found]   ` <97DC61EC-3DD4-444B-98DB-AB9A823EA1F3@sarc.name>
2021-12-09 20:34     ` Maxime Devos [this message]
2021-11-25 18:22 ` Maxime Devos
2021-11-25 18:56   ` lloda
2021-11-27  8:42     ` lloda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e8dbdf613b701a958dab5ce3db06a25b7e01dff9.camel@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=guile-devel@gnu.org \
    --cc=lloda@sarc.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).