Last active
December 14, 2015 19:29
-
-
Save shirok/5136967 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defmacro def-coords-macro (kind) | |
(let ((with-coords (intern (format nil "WITH-~a-COORDS" kind))) | |
(checking (intern (format nil "CHECKING-~a-COORDS" kind))) | |
(box (intern (format nil "BOX-~a" kind))) | |
(unbox (intern (format nil "UNBOX-~a" kind)))) | |
`(progn | |
(defmacro ,box (v) `(cons ',',kind ,v)) | |
(defmacro ,unbox (v) | |
(let ((vv (gensym))) | |
`(let ((,vv ,v)) | |
(if (consp ,vv) | |
(if (eq (car ,vv) ',',kind) | |
(cdr ,vv) | |
(error "~a coordinate expected, but got ~s" ',',kind ,vv)) | |
,vv)))) | |
(defmacro ,with-coords ((x y) &body body) | |
`(let ((,x (,',unbox ,x)) | |
(,y (,',unbox ,y))) | |
,@body)) | |
(defmacro ,checking ((x y) (def name args &body body)) | |
`(,def ,name ,args | |
(,',with-coords (,x ,y) ,@body)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment