Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goenningerf/da72dcba4db85b87eea963ba90868450 to your computer and use it in GitHub Desktop.
Save goenningerf/da72dcba4db85b87eea963ba90868450 to your computer and use it in GitHub Desktop.
Creating functions that return news wire instances with incf'd function names
(defclass counter-mixin ()
((counter :accessor counter :allocation :class :initarg :counter :type integer)))
(defmethod initialize-instance :after ((self counter-mixin) &key)
(if (slot-boundp self 'counter)
(incf (counter self))
(setf (counter self) 0)))
(defclass wire (counter-mixin)
())
(defmacro make-new-wire ()
(let* ((new-wire (make-instance 'wire))
(symbol-name (format nil "WIRE-~A" (counter new-wire))))
`(defun ,(intern symbol-name) ()
,new-wire)))
=>
CL-USER> (make-new-wire)
WIRE-14
CL-USER> (wire-14)
#<WIRE @ #x10003da8d72>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment