0

A cl-defstruct may create several functions. I would like to jump to the initial definition where everything is defined, similar to find-function. How can I do that?

  • You're probably better off asking @Stefan directly :P. – Tianxiang Xiong May 4 '17 at 5:34
  • My understanding is that these functions aren't defined in files, so, jumping to them is not possible. They exist as compiled objects in interpreter's memory. What you could do, is to call disassemble to see what the function will do. – wvxvw May 4 '17 at 14:28
1

This is not 100% what you want, but may still be of some interest. I don't think you can "jump" to the definition of a function defined in cl-defstruct macro, but you can still get some idea of what it does, for example, like this:

Suppose, you defined this struct:

(cl-defstruct foo bar)

Then, you would get, for example, also defined function foo-bar, you can look up its bytecode like this:

(disassemble #'foo-bar)
;; byte code for foo-bar:
;;   args: (cl-x)
;; 0       constant  vectorp
;; 1       varref    cl-x
;; 2       call      1
;; 3       goto-if-nil 1
;; 6       varref    cl-x
;; 7       length    
;; 8       constant  2
;; 9       geq       
;; 10      goto-if-nil 1
;; 13      varref    cl-x
;; 14      constant  0
;; 15      aref      
;; 16      varref    cl-struct-foo-tags
;; 17      memq      
;; 18      goto-if-not-nil 2
;; 21:1    constant  signal
;; 22      constant  wrong-type-argument
;; 23      constant  foo
;; 24      varref    cl-x
;; 25      list2     
;; 26      call      2
;; 27      discard   
;; 28:2    varref    cl-x
;; 29      constant  1
;; 30      aref      
;; 31      return    

This is roughly what this bytecode amounts to:

(defun foo-bar (cl-x)
  (if (and (vectorp cl-x)
           (>= (length cl-x) 2))
      (if (memq (aref cl-x 0) cl-struct-foo-tags)
          (progn
            (aref cl-x 1)
            (return)))
    (signal wrong-type-argument (list foo cl-x))))
  • Thank you -- I will add this to my arsenal of goodies. I had previously been relying only upon symbol-function to inspect whatever value is available from said function, but it is not as detailed as disassemble. – lawlist May 4 '17 at 16:27

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.