emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pure-fns in byte-opt.el


From: Philipp Stephani
Subject: Re: pure-fns in byte-opt.el
Date: Fri, 28 Jul 2017 17:45:48 +0000



Stefan Monnier <address@hidden> schrieb am Di., 25. Juli 2017 um 23:27 Uhr:
> Why? Its return value clearly only depends on its argument, and it doesn't
> change any global state. It's the poster child of a pure function!

  (let ((s (make-string 5 ?a)))
    (list (string-to-char s)
          (progn
            (aset s 0 ?b)
            (string-to-char s))))

If string-to-char were a pure function, it would return the same value
in both calls (since the arguments are `eq').


Hmm. I get the argument, but wouldn't that mean that only a tiny set of builtins were pure? If the definition is "A function is pure if applying it to the same objects (in the sense of `eq') always gives the same result", then I think only eq, eql, null, and the type predicates (integerp etc.) are pure. Even the arithmetic functions aren't pure because they can act on (mutable) markers. The list in byte-opt, however, is noticeably different, and none of the functions marked pure there are actually pure. The same applies to third-party libraries such as dash.el.
In any case, the precise definition of "pure" and "side effect free" needs to be in the manual, and functions that are wrongly declared as pure or side effect free need to be fixed. 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]