[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setf extensions (list cons values?)

How can I define a (setf values) extension in MCL 2.0b2 if define-setf-method
is not required to support more than one store variable?

The behavior that I would like is:

(let (x y z w) (setf (values x y) (setf (values z w) (values 'foo 'bar))) (list
x y z w)) 

should return '(foo bar foo bar).  Remember that the result of the setf form
needs to return multiple values as well.

Thanks for any help you can give me.

Below is some code showing what I was able to do for (setf list) and (setf


(define-setf-method list (&rest references)
  (let (local-vars value)
    (setf local-vars (loop 
                       for i from 1 to (length references) 
                       collect (gensym))
          value (gensym))
    (values local-vars
          nil;;;   references
            (list value)  
            `(apply #'(lambda (,@local-vars)
                             for local-var in local-vars
                             for ref in references
                             append `(,ref ,local-var))))
            `(list ,@local-vars))))

(define-setf-method cons (car cdr)
  (let (car-var cdr-var value)
    (setf car-var (gensym)
          cdr-var (gensym)
          value (gensym))
    (values (list car-var cdr-var)
            nil ;;; (list car cdr)
            (list value)  
            `(apply #'(lambda (,car-var &rest ,cdr-var) (setf ,car ,car-var
,cdr ,cdr-var)) 
            `(cons ,car-var ,cdr-var))))