atlas-engineer / nclasses

A `define-class` macro for less boilerplate
Other
7 stars 2 forks source link

define-generic fails with `declare`s #22

Closed Ambrevar closed 1 year ago

Ambrevar commented 1 year ago

This

(define-generic make-suggestion ((value t) &optional source input)
  "Return a `suggestion' wrapping around VALUE.
Attributes are set with `object-attributes'."
  (declare (ignore input))
  (make-instance 'suggestion
                 :value value
                 :attributes (object-attributes value source)))

expands to

(prog1
    (defgeneric make-suggestion
        (value &optional source input)
      (declare (ignore input))
      (:method ((value t) &optional source input)
       (make-instance 'suggestion :value value :attributes
                      (object-attributes value source)))
      (:documentation "Return a `suggestion' wrapping around VALUE.
Attributes are set with `object-attributes'."))
  (setf (documentation 'make-suggestion 'function)
          "Return a `suggestion' wrapping around VALUE.
Attributes are set with `object-attributes'.")
  (setf (documentation (fdefinition 'make-suggestion) 'function)
          "Return a `suggestion' wrapping around VALUE.
Attributes are set with `object-attributes'."))

The declare is misplaced. The docstring says:

    - If there's a `declare' form, it's put as a `declare' option of
      `defgeneric'. This may seem irregular if the method body also needs
      declarations, but in such a case one's better off with a :method
      option or `defgeneric' for the method with `declare'.

But that does not seem right. @aartaka Can you explain the rationale?

aartaka commented 1 year ago

Generics have their own declarations. Although they are restricted, they are still quite global.

Actually, I've just gotten a revelation: we can parse these declares (due to their regular syntax), and

Does that sound right?

aartaka commented 1 year ago

Done with 59166973b5ba14275c60cc941bd9558bdbd0e1a5 and 12c183e8e53d243ea250f190d9d1cac6f1c6de56!

Ambrevar commented 1 year ago

Can't we use alex:parse-body?

Ambrevar commented 1 year ago

@aartaka Friendly ping :)

aartaka commented 1 year ago

Can't we use alex:parse-body?

No, we can't, because it's not a dependency of nclasses \~_\~

Ambrevar commented 1 year ago

Hmmm... Wondering if it wouldn't be worth adding. It might dramatically simplify this code.

aartaka commented 1 year ago

Yes, it for sure could...

aartaka commented 1 year ago

Waaaaaaaaaaaaaaait... There's uiop:parse-body!!!!!!!!

aartaka commented 1 year ago

Fixed in f8ec8dca98344de55c087000c82026e1ddb32888! define-generic implementation finally sparks joy :D