all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
To: emacs-devel@gnu.org
Cc: Mark Oteiza <mvoteiza@udel.edu>, Andreas Schwab <schwab@suse.de>
Subject: Re: pure-fns in byte-opt.el
Date: Wed, 26 Jul 2017 09:39:00 +0200	[thread overview]
Message-ID: <7ef8e35a-d236-5158-f2eb-85f01da87a2e@gmail.com> (raw)
In-Reply-To: <jwvk22wm55q.fsf-monnier+gmane.emacs.devel@gnu.org>

On 2017-07-26 02:08, Stefan Monnier wrote:
>>> If string-to-char were a pure function, it would return the same
>>> value in both calls (since the arguments are `eq')
>>                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> What do you mean by this?
> 
> That the argument passed to the first call is `eq` with the argument
> passed to the second call.

I see.  That's not what I understood to be usually meant by "pure": although both arguments are pointers to the same address in memory, the contents of that address have been modified in the meantime.  In that sense, haven't the two calls to string-to-char been passed different values (albeit stored in the same memory location)?

In other words, I don't see your example as proving that string-to-char is impure; instead, it just looks like a pure function that's passed two different values.  As a concrete example, is the following a proof that string-to-syntax is impure? If so, it should be removed from our list of pure functions :)

  (let ((s (make-string 1 ?w)))
    (list (string-to-syntax s)
          (progn
            (aset s 0 ?_)
            (string-to-syntax s))))

The same argument seems to apply to *all* functions marked pure in byte-opt.el, except `symbol-name' (namely `concat', `regexp-opt', `regexp-quote', and `string-to-syntax'). Under your definition, neither the `length' nor the `car' function on lists are pure. In fact, if I understand it correctly, your definition seems to imply that any function that reads mutable data is (by definition) impure.  Is that right?  This seems very restrictive, and it seems to be contradicted by existing 'pure' annotations in our codebase.  How do we call the property shared by `concat', `length', and `string-to-chars'? in ELisp land, if it's not "pure"?

In byte-opt we say this:

;; pure functions are side-effect free functions whose values depend
;; only on their arguments. For these functions, calls with constant
;; arguments can be evaluated at compile time. This may shift run time
;; errors to compile time.

I tried to get inspiration from looking at other `pure' annotations in lisp/ but the examples I found were confusing.  All four examples of (pure t) functions in smie.el take lists as input, for example:

(defun smie-precs->prec2 (precs)
  "Compute a 2D precedence table from a list of precedences. …
  (declare (pure t))

and indeed:

  (let ((s '((left "+") (right "*"))))
    (list (smie-precs->prec2 s)
          (progn
            (setf (caar s) 'right)
            (smie-precs->prec2 s))))

Can you point out where I went wrong? To me it just looks like Mark ran into a bug.

Clément.



  reply	other threads:[~2017-07-26  7:39 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25  2:06 pure-fns in byte-opt.el Mark Oteiza
2017-07-25  8:14 ` Andreas Schwab
2017-07-25 14:16   ` Stefan Monnier
2017-07-25 20:57     ` Philipp Stephani
2017-07-25 21:27       ` Stefan Monnier
2017-07-25 22:28         ` Clément Pit-Claudel
2017-07-26  0:08           ` Stefan Monnier
2017-07-26  7:39             ` Clément Pit-Claudel [this message]
2017-07-26 12:58               ` Stefan Monnier
2017-07-28 17:45         ` Philipp Stephani
2017-07-28 17:49           ` Stefan Monnier
2017-07-28 17:52             ` Philipp Stephani
2017-07-28 22:20               ` Stefan Monnier
2017-09-24  7:31                 ` Philipp Stephani
2017-09-24 16:23                   ` Stefan Monnier
2017-09-25 22:06                     ` Richard Stallman
2017-09-26  0:25                       ` Stefan Monnier
2020-07-25 19:53                         ` Philipp Stephani
2020-07-25 19:58                           ` Stefan Monnier
2020-07-25 20:08                             ` Philipp Stephani
2020-07-25 20:59                               ` Stefan Monnier
2020-07-29 14:21                                 ` Philipp Stephani
2020-07-29 14:25                                   ` Stefan Monnier
2017-09-24 16:26                   ` Drew Adams
2017-07-26  1:00   ` Mark Oteiza
2017-07-26 14:33     ` Eli Zaretskii
2017-07-27  2:36       ` Mark Oteiza
2017-07-27  2:46         ` Stefan Monnier
2017-07-29 16:43           ` Mark Oteiza
2017-07-29 17:22             ` Eli Zaretskii
2017-07-29 19:48               ` Mark Oteiza
2017-07-29 20:03                 ` Andreas Schwab
2017-07-29 20:14                   ` Mark Oteiza
2017-07-27 17:06         ` Eli Zaretskii
2017-07-28  0:24           ` Mark Oteiza
2017-07-28  7:02             ` Eli Zaretskii
2017-07-29  1:24               ` Mark Oteiza
2017-07-29  7:24                 ` Eli Zaretskii
2017-07-29 16:34                   ` Mark Oteiza
2017-07-29 17:21                     ` Eli Zaretskii
2017-09-24  7:34                       ` Philipp Stephani
2017-09-24 16:24                         ` Stefan Monnier
2017-09-24 23:22                         ` John Wiegley

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

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

  git send-email \
    --in-reply-to=7ef8e35a-d236-5158-f2eb-85f01da87a2e@gmail.com \
    --to=cpitclaudel@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=mvoteiza@udel.edu \
    --cc=schwab@suse.de \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.