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?

  • Take look at this: gnu.org/software/emacs/manual/html_node/elisp/… – user12563 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
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.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.