Skip to content

Please update defclass-std source #2454

@vindarel

Description

@vindarel

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

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions