(ql:quickload :place-utils) ;; A "conditional place" (define-setf-expander iff (cond then-place else-place &environment env) (multiple-value-bind (temps1 exprs1 stores1 set1 get1) (get-setf-expansion then-place env) (multiple-value-bind (temps2 exprs2 stores2 set2 get2) (get-setf-expansion else-place env) (unless (= (length stores1) (length stores2)) (error "The places must have an equal number of stores")) (let ((cond-sym (gensym))) (values (append (list cond-sym) temps1 temps2) (append (list cond) (mapcar (lambda (e) `(when ,cond-sym ,e)) exprs1) (mapcar (lambda (e) `(unless ,cond-sym ,e)) exprs2)) stores1 `(if ,cond-sym ,set1 (let ,(mapcar #'list stores2 stores1) ,set2)) `(if ,cond-sym ,get1 ,get2)))))) (defmacro iff (cond then-place else-place) `(place-utils:readf (iff ,cond ,then-place ,else-place))) (let ((a (cons 1 2))) (format t "cons: ~a~%" a) (setf (iff t (car a) (cdr a)) 20) (format t "cons: ~a~%" a) (format t "read: ~a~%" (iff t (car a) (cdr a))) (format t "read: ~a~%" (iff nil (car a) (cdr a))))