A compiled program and a source code can be interpreted differently at runtime. The issue is that some Lisp objects should not be modified because of the byte-compilation.

Emacs Lisp manual: 2.7 Equality Predicates

The Emacs Lisp byte compiler may collapse identical literal objects, such as literal strings, into references to the same object, with the effect that the byte-compiled code will compare such objects as eq, while the interpreted version of the same code will not. Therefore, your code should never rely on objects with the same literal contents being either eq or not eq, it should instead use functions that compare object contents such as equal, described below. Similarly, your code should not modify literal objects (e.g., put text properties on literal strings), since doing that might affect other literal objects of the same contents, if the byte compiler collapses them.

This does not imply that all Lisp objects are necessarily byte-compiled but the byte-compilation can change the code somehow.

Emacs Lisp manual: 17 Byte Compilation

Emacs Lisp has a "compiler" that translates functions written in Lisp into a special representation called "byte-code" that can be executed more efficiently. The compiler replaces Lisp function definitions with byte-code. When a byte-code function is called, its definition is evaluated by the "byte-code interpreter".

I think that the compiled code is read only once but may be evaluated several times.

In addition, in general, there are not only primitive objects. In the broader sense, which Lisp objects are byte-compiled? For example, are literal objects all and always byte-compiled?

Let's end with two final observations. 1. The Elisp manual shows that we can modify literal lists bound to variables. 2. Previously, lambda expressions had to be specified as functions '#(lambda ...) in order to be byte-compiled.

Note: From my point of view, a "byte-compiled object" can be a special object created because of the byte-compilation (e.g. a byte-compiled function) or any object that appears only during the byte-compilation (e.g. a constant object).

  • 1
    Hi Fólkvangr, this question is a substantial step towards answering the other question (+1). The general requirement "your code should not modify literal objects" marks those parts of the manual as buggy, where literal lists are modified. Or let us say that those parts work because they are not byte-compiled. Then they leave the reader with bad habits when he later wants to write code to be byte-compiled.
    – Tobias
    Apr 15 '20 at 11:51
  • 1
    One thing we learn from this: Luckily propertize returns a copy. But, setting a variable to a literal string and then calling put-text-property with that variable as optional arg OBJECT should be avoided. -- Good to know.
    – Tobias
    Apr 15 '20 at 12:00
  • If the current elisp manual on master shows buggy example code, please let the Emacs devs know via either M-x report-emacs-bug or email to emacs-devel@gnu.org
    – rpluim
    Apr 15 '20 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy