unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Phil Hagelberg <phil@hagelb.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Kickstarter for Emacs
Date: Sun, 22 Apr 2012 22:17:22 -0700	[thread overview]
Message-ID: <CAK4J7B_BGEGmH+Zer4br+bU8KJnUWL4fwR3aG7+eBcQ2icD+cg@mail.gmail.com> (raw)
In-Reply-To: <jwvhawdstat.fsf-monnier+emacs@gnu.org>

On Fri, Apr 20, 2012 at 7:46 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> My own local hacked version of Emacs has aset signal an error when
> called on a string (and subst-char-in-string also signals as error when
> called with `inplace').  I rarely bump into problems because of
> this change.
> But note that strings include text-properties, and I still allow those
> to be changed.  Making them immutable would break more code (since
> until `propertize' was added, all the text-properties were manipulated
> by side-effects).

Very interesting! Now that I think of it I haven't actually seen any
code that destructively updates strings other than text-properties as
you say. But given that equality already doesn't take these into
account, this is probably OK. In fact, Baker's paper addresses this
notion directly: "Obviously, material properties--being
contingent--cannot contribute to an object's identity, while formal
properties--being necessary--are an inherent part of an object's
identity."

I'd be interested in trying this patch if you could share it. Are you
fairly sure that those are the only existing functions which can
change the value of a string?

> For `cons' cells, side-effects are used much too often in Elisp,
> I wouldn't hold much hope for making them immutable.  So immutable cells
> would have to be a new type (and car/cdr could be made to work with
> them as well) with a new constructor (maybe named `icons' or `pair').

Indeed; this is a stickier issue. While I wouldn't expect it to be
feasible to change the default, the availability of a separate type of
cons cell upon which destructive operations could not act would be
wonderful provided the nondestructive list operations would still
work. I wonder if it wouldn't be possible to set a file-local variable
that could make the reader return immutable lists while loading that
file, much like the way lexical scoping was introduced in an opt-in
way to reduce breakage.

> The problem still remains: what would be the benefit?

I must confess this is difficult for me to express, simply because
it's something I've taken for granted for so long; it's like being
asked why I like garbage collection. Anyhow, the most obvious benefit
would be that you have a chance at writing code that you know will
function correctly while run concurrently. =)

But while the reduced complexity of referentially transparent
functions is subtler (and more difficult to explain without trying it
for yourself), I think it's no less compelling. The idea that you can
hand an argument to a function and not have to consider whether it's
going to change relieves you of a fair amount of needless mental
overhead while coding and makes certain classes of bugs impossible.
Essentially you can eliminate the difference between call-by-value and
call-by-reference. You can't write referentially transparent functions
that treat mutable objects as equivalent, because these functions will
not always return the same value when called with the same arguments
at different times.

The other benefit of immutable objects is that it allows you to do
away with the confusing eq/eql/equal distinction. This is the main
point of Baker's paper. He makes a compelling case that the usefulness
of hash tables in CL (and Elisp by extension) are severely limited by
having to pick a test function up-front. If you pick a test that is
too fine-grained (like eq or eql), then you are unable to use things
like strings as keys, but if you pick a test that is too coarse like
equal, then you will have false positives when you pass in a different
list that happens to have the same value at the time of the call. The
presence of immutable values allows you to define an equality
predicate that works in terms of operational equivalence, which is far
more useful.

Of course, in a way this amounts to turning Elisp into a functional
language, or possibly a language in which "mostly functional"
programming is encouraged. You could argue that it would be turning
Elisp into something that it isn't; perhaps this is fair. (I can just
go back to writing my Clojure code, but I really like Emacs as a
runtime.) Maybe I should just wait for Guile to gain the capability to
run Elisp, since that would be another way to achieve this goal. I'm
not sure it's the right thing for Emacs given the constraints of
legacy code and the limited time of its developers, but I am fairly
convinced it's a better design for languages in general.

-Phil



  reply	other threads:[~2012-04-23  5:17 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-18  7:08 Kickstarter for Emacs Tom
2012-04-18  7:50 ` Tom
2012-04-18  8:59   ` Chong Yidong
2012-04-18  9:25     ` Tom
2012-04-18  9:38       ` Vyacheslav Gonakhchyan
2012-04-18  9:43         ` Tom
2012-04-18 10:14           ` Vyacheslav Gonakhchyan
2012-04-18 10:34             ` Tom
2012-04-18 11:00               ` Jambunathan K
2012-04-18 11:20                 ` Tom
2012-04-18 11:39                   ` Jambunathan K
2012-04-18 13:10               ` Tassilo Horn
2012-04-18 13:47                 ` Tom
2012-04-18 14:19                   ` Nikodemus Siivola
2012-04-18 14:57                     ` Tom
2012-04-18 22:09                       ` Phil Hagelberg
2012-04-19 21:02                         ` Stefan Monnier
2012-04-21  0:10                           ` Phil Hagelberg
2012-04-21  2:46                             ` Stefan Monnier
2012-04-23  5:17                               ` Phil Hagelberg [this message]
2012-04-23  8:17                                 ` Guile based Elisp faster? (was Re: Kickstarter for Emacs) Thorsten
2012-04-24 11:35                                   ` Guile based Elisp faster? Andy Wingo
2012-04-24 17:46                                     ` Thorsten Jolitz
2012-04-24  2:01                                 ` Kickstarter for Emacs Stefan Monnier
2012-04-25 16:33                                   ` Phil Hagelberg
2012-04-19  0:45                     ` Richard Stallman
2012-04-19  6:23                       ` [PROPOSAL] GSoC-like campaingn for FSF/GNU projects Jambunathan K
2012-04-19 17:54                         ` Bastien
2012-04-19 18:38                         ` Richard Stallman
2012-04-19 11:58                       ` Kickstarter for Emacs Nikodemus Siivola
2012-04-19 18:38                         ` Richard Stallman
2012-04-18 14:27                   ` Tassilo Horn
2012-04-18 14:50                     ` Tom
2012-04-23  9:23                     ` Steinar Bang
2012-04-23  9:20                       ` Tassilo Horn
2012-04-19 12:47                   ` Richard Riley
2012-04-18 22:39               ` Bastien
2012-04-18 14:33       ` Eric Schulte
2012-04-19  0:45         ` Richard Stallman
2012-04-19  5:28         ` Tom
2012-04-19  6:05           ` Jambunathan K
2012-04-19 18:38           ` Richard Stallman
2012-04-19 19:04             ` Tom
2012-04-25 19:56     ` Jordi Gutiérrez Hermoso
2012-04-18 18:25   ` Richard Stallman
2012-04-18 11:25 ` Jambunathan K
2012-04-18 13:34   ` Tom
2012-04-18 16:08 ` Ivan Andrus
2012-04-18 16:24   ` Drew Adams
2012-04-18 18:49   ` Andreas Röhler
2012-04-18 19:04   ` aaditya sood
2012-04-18 19:44     ` Andreas Röhler
2012-04-19  1:50   ` Chong Yidong
2012-04-19  5:13     ` Andreas Röhler
2012-04-19 15:22     ` Rasmus
2012-04-19 16:10     ` Ivan Andrus
2012-04-19 22:07       ` Stefan Monnier
2012-04-20  7:33         ` Ivan Andrus

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/emacs/

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

  git send-email \
    --in-reply-to=CAK4J7B_BGEGmH+Zer4br+bU8KJnUWL4fwR3aG7+eBcQ2icD+cg@mail.gmail.com \
    --to=phil@hagelb.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).