I'm trying to make macros for defining various object similar to defparameter and defvar. The defregion1 macro works: upon executing it defines a variable with object region. However, defregion2 only returns an expression that must be executed manually. Here is the code:
(defclass location () ((x :initarg :x :accessor x) (y :initarg :y :accessor y))) (defclass region () ((x :initarg :x :accessor x) (y :initarg :y :accessor y) (w :initarg :w :accessor w) (h :initarg :h :accessor h))) (defmacro deflocation (var x y) `(defparameter ,var `(make-instance 'location :x ,x :y ,y))) (defmacro defregion1 (var x y w h) `(defparameter ,(intern (symbol-name var)) (make-instance 'region :x ,x :y ,y :w ,w :h ,h))) (defmacro defregion2 (var l1 l2) `(with-slots ((x1 x) (y1 y)) ,l1 (with-slots ((x2 x) (y2 y)) ,l2 `(defparameter ,(intern (symbol-name ,var)) (make-instance 'region :x ,x1 :y ,y1 :w (- ,x2 ,x1) :h (- ,y2 ,y1)))))) The output of defregion1:
(defregion1 *test-reg1* 1 2 3 4) => *test-reg1* The output of deferegion2:
(deflocation *l1* 20 30) (deflocation *l2* 50 60) (defregion2 '*test-reg2* *l1* *l2*) => (DEFPARAMETER *TEST-REG2* (MAKE-INSTANCE 'REGION :X 20 :Y 30 :W (- 50 20) :H (- 60 30))) I want *test-reg2* to also become a variable. What is wrong here?