atlas-engineer / nclasses

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

Inline class/condition documentation #20

Open aartaka opened 1 year ago

aartaka commented 1 year ago

We already have a documentation shortcut in define-generic, allowing documentation after the initial generic declaration:

(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)
  "Adds A and B, coercing them to fixnum if the sum is too big."
  (if coerce-to-fixnum
      (coerce (+ a b) 'fixnum)
      (+ a b)))

This usefully expands to the proper :documentation option of defgeneric.

This inline syntax would be useful in define-class/define-condition*, and is exemplified by Nyxt's define-mode already:

(define-mode annotate-mode ()
  "Annotate document with arbitrary comments.
Annotations are persisted to disk, see the `annotations-file' mode slot.

Commands are:
- `annotate-current-url' and `annotate-highlighted-text' to create
  annotations.
- `show-annotation' and `show-annotations' to show the annotations
  unconditionally.
- And `show-annotations-for-current-url' to show the ones associated with the
  current page."
  #|...|#)

Would be nice to make it native to define-class for even more brevity and ease of use. The downside is that the signature becomes less exact.

Ambrevar commented 1 year ago

Good idea!