[Small-cl-src] Re: What would var+++ be in CL?

Lars Brinkhoff lars at nocrew.org
Wed Jul 6 18:15:27 UTC 2005


Ingvar <ingvar at cathouse.bofh.se> writes:
> ;;; Possibly a tad naive, but...
> (defmacro post-incf (form &optional (increment 1))
>   (let ((value (gensym "POST-INCF")))
>     `(let ((,value ,form))
>        (prog1 ,value (setf ,form (+ ,value ,increment))))))

;;; Possibly a tad less naive...
(defmacro post-incf (form &optional (increment 1) &environment env)
  (with-gensyms (result)
    (multiple-value-bind (temps vals vars writer reader)
        (get-setf-expansion form env)
      `(let* (,@(mapcar #'list temps vals)
              (,result ,reader)
              (,(first vars) (+ ,result ,increment)))
        ,writer
        ,result))))





More information about the Small-cl-src mailing list