Search code examples
macroslispcommon-lispccl

Getting error when loading a lisp macro: Error: Class named ENTITY not found. While executing: FIND-CLASS, in process Listener(4)


I get this error:

Error: Class named ENTITY not found. While executing: FIND-CLASS, in process Listener(4). Type cmd-/ to continue, cmd-. to abort, cmd-\ for a list of available restarts. If continued: Try finding the class again Type :? for other options.

When I load/compile a file with this macro in it:

(defmacro def-post-entity (entity)
   (let* ((repository-var-name (cl-ddd::repository-var entity))
          (base-url (string-downcase (concatenate 'string "/api/" (string entity))))
          (progn-statement '(progn)))
     (loop 
       for slot in (ccl:class-slots (find-class entity)) 
       append `(setf (,(ccl:slot-definition-name slot) new-entity)  
               (cdr (assoc ,(string (ccl:slot-definition-name slot)) params :test #'string=)))
       into progn-statement)
      `(setf (ningle:route cl::*app* ,base-url :method :post)
             (lambda (params)
               (let ((new-entity (make-instance ,entity)))
                 (,progn-statement))))))

As I understand lisp macros (I'm new), there's no reason for find-class to expect entity to be a classname, it's a parameter to the macro. The error message indicates that find-class is being executed, but it's not. I'm just loading the file containing this macro via (ql:quickload "filename") or compile it directly.

Any help would be appreciated in helping me to understand what's happening, and to fix it.


Solution

  • The problem was the macro AFTer this one, where I call def-post-entity. It's a macro as well, and I forgot that that would mean def-post-entity gets expanded there as well.
    Coredumps comment helped me figure it out.