unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure functions
@ 2021-12-01 10:29 Andrea Corallo
  2021-12-01 20:32 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Andrea Corallo @ 2021-12-01 10:29 UTC (permalink / raw)
  To: 52220

[-- Attachment #1: Type: text/plain, Size: 115 bytes --]

Hi all,

shouldn't we declare structure predicates as pure functions?

Proposed patch attached.

Thanks

  Andrea


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-emacs-lisp-cl-macs.el-cl-defstruct-Decl-struct-.patch --]
[-- Type: text/x-diff, Size: 911 bytes --]

From 8382e2078295d6feb4abbe72cf671a61a84fc640 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <akrl@sdf.org>
Date: Wed, 1 Dec 2021 11:23:25 +0100
Subject: [PATCH] * lisp/emacs-lisp/cl-macs.el (cl-defstruct): Decl struct
 predicates as pure

---
 lisp/emacs-lisp/cl-macs.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 1852471bcb..9c9a778f04 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -3050,7 +3050,7 @@ cl-defstruct
                             `(,predicate cl-x))))
     (when pred-form
       (push `(,defsym ,predicate (cl-x)
-               (declare (side-effect-free error-free))
+               (declare (side-effect-free error-free) (pure t))
                ,(if (eq (car pred-form) 'and)
                     (append pred-form '(t))
                   `(and ,pred-form t)))
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure functions
  2021-12-01 10:29 bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure functions Andrea Corallo
@ 2021-12-01 20:32 ` Lars Ingebrigtsen
  2021-12-01 21:05   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-01 21:16   ` Andrea Corallo
  0 siblings, 2 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-01 20:32 UTC (permalink / raw)
  To: Andrea Corallo; +Cc: 52220, Stefan Monnier

Andrea Corallo <akrl@sdf.org> writes:

> shouldn't we declare structure predicates as pure functions?

I think that's correct?  The predicates take the struct as the argument,
so they seem like pure functions to me.  I've added Stefan to the CCs;
perhaps there's some subtlety here I don't see.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure functions
  2021-12-01 20:32 ` Lars Ingebrigtsen
@ 2021-12-01 21:05   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-12-01 21:23     ` Andrea Corallo
  2021-12-01 21:16   ` Andrea Corallo
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-01 21:05 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 52220, Andrea Corallo

Lars Ingebrigtsen [2021-12-01 21:32:43] wrote:
> Andrea Corallo <akrl@sdf.org> writes:
>> shouldn't we declare structure predicates as pure functions?
> I think that's correct?

Sounds right, yes.


        Stefan






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure functions
  2021-12-01 20:32 ` Lars Ingebrigtsen
  2021-12-01 21:05   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-12-01 21:16   ` Andrea Corallo
  1 sibling, 0 replies; 5+ messages in thread
From: Andrea Corallo @ 2021-12-01 21:16 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 52220, Stefan Monnier

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Andrea Corallo <akrl@sdf.org> writes:
>
>> shouldn't we declare structure predicates as pure functions?
>
> I think that's correct?  The predicates take the struct as the argument,
> so they seem like pure functions to me.  I've added Stefan to the CCs;
> perhaps there's some subtlety here I don't see.

Yes we have all conventional predicates as pure, the only difference is
that here the result of the predicate depends also on the global state.

IOW redefining a structure could change the result of a predicate, but
my guess is that we don't want to be robust against that (structs in
general AFAIK are not robust against run-time redefinition).

  Andrea





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure functions
  2021-12-01 21:05   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-12-01 21:23     ` Andrea Corallo
  0 siblings, 0 replies; 5+ messages in thread
From: Andrea Corallo @ 2021-12-01 21:23 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 52220-done, Stefan Monnier

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> Lars Ingebrigtsen [2021-12-01 21:32:43] wrote:
>> Andrea Corallo <akrl@sdf.org> writes:
>>> shouldn't we declare structure predicates as pure functions?
>> I think that's correct?
>
> Sounds right, yes.
>
>
>         Stefan

Right, installed as c35c86a353, closing.

Thanks

  Andrea





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-01 21:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 10:29 bug#52220: 29.0.50; [PATCH] Declare struct predicates as pure functions Andrea Corallo
2021-12-01 20:32 ` Lars Ingebrigtsen
2021-12-01 21:05   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-01 21:23     ` Andrea Corallo
2021-12-01 21:16   ` Andrea Corallo

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