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: Sun, 24 Sep 2017 07:31:42 +0000

Stefan Monnier <address@hidden> schrieb am Sa., 29. Juli 2017 um 00:21 Uhr:
> So what is then the actual definition? Is it in the manual?

The only definition I've seen just says that it means that the compiler
can precompute the calls if it knows the arguments's values.


Can we find a definition that allows authors of functions to derive their "pure" and "side-effect-free" status by only looking at their interface and implementation? It seems like these attributes would both be useful for documentation purposes as well as for optimization, and they have seen some use outside of Emacs core (e.g. in dash.el), so their semantics should be formalized and documented. How about something like this:

A side-effect-free function is one where all of the following is true:
- After exiting the function (whether normally or nonlocally), the `match-data' are `equal' to the `match-data' before entering the function.
- After exiting the function, all dynamic variables, their default values, their symbol cells, etc., are `eq' to the respective values before entering the function. Exceptions are variables only used for debugging/tracing, such as `cons-cells-consed'.
- All buffer contents, markers, point values etc. are `equal-including-properties' to their previous values.
- The same buffers and threads still exist.

A side-effect-free-and-error-free function is one that is side-effect-free and also doesn't signal any errors except `memory-full'.

A pure function is a side-effect-free function with the following additional properties:
- The function recursively only accepts and returns numbers, symbols, lists, vectors, hashtables, and strings; not buffers or processes since they are naturally stateful.
- Two invocations with arguments that are pairwise `equal-including-properties' (or, in the case of hashtables, have keys and values that are `equal-including-properties') will either both exit nonlocally or return values that are again `equal-including-properties'.

reply via email to

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