quicklisp-projects icon indicating copy to clipboard operation
quicklisp-projects copied to clipboard

Please update `defclass-std` source

Open vindarel opened this issue 1 year ago • 4 comments

defclass-std provides a shorter defclass macro, and now a define-print-object/std macro.

  • old source: https://github.com/EuAndreh/defclass-std but they archived the repository. So I didn't ping them.
  • new source: https://github.com/lisp-maintainers/defclass-std where I added the short PRINT-OBJECT macro. The lisp-maintainers org isn't tied to one person.
(defclass/std example ()
  ((slot1 slot2 slot3)))

;; even shorter:
;; (class/std classname slot1 slot2 slot3)

(define-print-object/std example)

expands to

(DEFCLASS EXAMPLE ()
  ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
   (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
   (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))

(defmethod print-object ((obj example) stream)
    (print-unreadable-object (obj stream :type t :identity t)
        (format stream \"~{~a~^ ~}\" (collect-object-slots obj))))

result:

(make-instance 'example)
;; #<EXAMPLE (SLOT1 NIL) (SLOT2 NIL) (SLOT3 NIL) {100ADFFF73}>

While certainly a rite of passage, having such a quick macro is nice for prototyping and the upcoming AOC :p

Comparison to other libraries: this one is very light on dependencies and doesn't go too far.

vindarel avatar Nov 29 '24 11:11 vindarel