Created
June 29, 2019 11:12
-
-
Save goenningerf/da72dcba4db85b87eea963ba90868450 to your computer and use it in GitHub Desktop.
Creating functions that return news wire instances with incf'd function names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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