From: David Vázquez Date: Thu, 25 Apr 2013 22:01:15 +0000 (+0100) Subject: INCF and DECF work on proper places X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=b5ea0102bc06080b0ad3d0fa3bf11175c21a3380;p=jscl.git INCF and DECF work on proper places --- diff --git a/src/boot.lisp b/src/boot.lisp index d57fa0b..0fc7a40 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -154,11 +154,25 @@ ;; Basic macros -(defmacro incf (x &optional (delta 1)) - `(setq ,x (+ ,x ,delta))) +(defmacro incf (place &optional (delta 1)) + (multiple-value-bind (dummies vals newval setter getter) + (get-setf-expansion place) + (let ((d (gensym))) + `(let* (,@(mapcar #'list dummies vals) + (,d ,delta) + (,(car newval) (+ ,getter ,d)) + ,@(cdr newval)) + ,setter)))) -(defmacro decf (x &optional (delta 1)) - `(setq ,x (- ,x ,delta))) +(defmacro decf (place &optional (delta 1)) + (multiple-value-bind (dummies vals newval setter getter) + (get-setf-expansion place) + (let ((d (gensym))) + `(let* (,@(mapcar #'list dummies vals) + (,d ,delta) + (,(car newval) (- ,getter ,d)) + ,@(cdr newval)) + ,setter)))) (defmacro push (x place) (multiple-value-bind (dummies vals newval setter getter)