4

Given a function that calls not:

(defun my-not (x)
  (not x))

M-x disassemble gives:

byte code for my-not:
  doc:   ...
  args: (arg1)
0       dup       
1       not       
2       return    

I was surprised that this didn't do:

constant not
stack-ref 1
call 1

because otherwise I cannot redefine not and affect the original function.

I imagine this is done for performance. Which functions does apply to, and where it is it documented?

Wilfred Hughes
  • 6,920
  • 2
  • 31
  • 60
  • Take look at this: https://www.gnu.org/software/emacs/manual/html_node/elisp/Primitive-Function-Type.html –  Jan 17 '17 at 22:54
  • @DoMiNeLa10 that's interesting, but it does say "Calls to the redefined function from Lisp will use the new definition". I'm calling the function from lisp here, but it won't use the new definition. – Wilfred Hughes Jan 17 '17 at 23:20

1 Answers1

5

If you look at (symbol-plist 'not) you will see that it has a byte-opcode property with value byte-not. So the elisp compiler will use this rather than a general function call.

I have not looked for documentation.

If you look at the lisp/emacs-lisp/bytecomp.el file in the source you will find a whole series of byte-XXXX values which are used in this way, so for example (point-min) is also compiled to a single byte rather than a generic function call.

icarus
  • 1,914
  • 1
  • 10
  • 16