guicho271828 / trivia

Pattern Matcher Compatible with Optima
Other
332 stars 22 forks source link

Symbol is unbound in namespace pattern #142

Closed charJe closed 1 year ago

charJe commented 1 year ago

This error seems to only happen when the file is compiled with asdf. It does not happen if the file is loaded with load. If get-bar is moved to another file that is compiled after, there is no error.

(defclass foo ()
  ((bar
    :initarg :bar
    :reader bar)))

(defmethod get-bar (thing)
  (ematch thing
    ((foo :bar bar)
     bar)))
; in: defmethod get-bar
;     (TRIVIA.LEVEL2:EMATCH THING
;       ((FOO :BAR BAR)
;        BAR))
; 
; caught error:
;   (during macroexpansion of (sb-pcl::%defmethod-expander get-bar ...))
;   Symbol foo is unbound in namespace pattern
guicho271828 commented 1 year ago

You must wrap defclass in eval-when

charJe commented 1 year ago

That seems like more of a work around. Is there a better solution?

guicho271828 commented 1 year ago

In order for the matcher to recognize the class and expand the form into a correct code, the class must be defined at the time of the expansion. This fact itself has no workaround.

Another way to fix this is to move the class definition into a separate file and make sure ASDF loads it before compiling this file.

charJe commented 1 year ago

I see. That is unfortunate.

charJe commented 1 year ago

I was just looking at find-class and saw that it has an environment parameter. I didn't see a way to use it for sensing compiled defclass forms though. 😿