Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!news.nic.surfnet.nl!sun4nl!aie.nl!news
From: geert@sparc.aie.nl (Geert-Jan van Opdorp)
Subject: setf and multiple values
Sender: news@aie.nl (News Account)
Organization: AI Engineering BV
Lines: 58
Message-ID: <GEERT.95May3115740@sparc.aie.nl>
Date: Wed, 3 May 1995 09:57:40 GMT


Hi,

I have been experimenting writing setf methods
for `places' that hold multiple values. 
I encountered the following problem: because
in `define-setf-method' I have to give a list of
storage-variables, I have to either know how many
will be stored, or just giving a large amount
of variables and just hope it will suffice.

For example:

This is no problem because `places' tell me the
maximum needed storage-variables:

(define-setf-method values (&rest places)
  (let* ((methods (mapcar #'(lambda (place)
			      (multiple-value-list (get-setf-method place)))
		          places))
	 (tmps       (apply #'append (mapcar #'first  methods)))
	 (val-forms  (apply #'append (mapcar #'second methods)))
	 (store-vars (apply #'append (mapcar #'third  methods)))
	 (store-forms  (mapcar #'fourth methods))
	 (access-forms (mapcar #'fifth  methods))
	 (store-form `(progn ,@store-forms
		             (values ,@store-vars)))
	 (access-form `(values ,@access-forms)))
    (values tmps val-forms store-vars store-form access-form)))

But this is a problem:

(define-setf-method values-list (l)
  (let* ((tmps (list (gensym)))
	 (val-forms (list l))
         ;; Here I can't think of anything than 
         ;;  just providing lots of gensyms...
	 (store-vars (list (gensym) (gensym) (gensym) 
                           (gensym) (gensym) (gensym)))
	 (store-form `(progn (mapl #'(lambda (sub-l store)
				       (setf (car sub-l) (car store))
				       ,(car tmps)
				       ,store-vars))
		       (values ,@store-vars)))
	 (access-form `(values-list ,(car tmps))))
    (values tmps val-forms store-vars store-form access-form)))

Is there a better way? Or do I want the impossible?
Any light on this I would greatly appreciate!

Thanks,

Geert-Jan.
-- 
Geert-Jan van Opdorp
AI-Engineering
Amsterdam, The Netherlands
geert@aie.nl
