From: Dan Stanger
Subject: structure/class assignments
Date: 
Message-ID: <3uelit$njg@teal.csn.net>
i have data that is presented to me in a list which i had intended
to put into a structure.  the structure elements are
month day year hours minutes dur-hour dur-tenths tgn
i could also put this into a clos class.
i then want to store them into a record/class with the following elements.
month day year hours minutes duration tgn
where duration = dur-hour*600 + dur-tenths.
my first structure is l and my second structure is c.  is it possible to
code this so i dont have to refer to each element of the structure in the
assignment so i can assign month to month, day to day ... except for
the duration where i need to execute the above formula for duration?
or possibly to automaticly generate the assignment code with a macro
except doing something special for duration?
thanks,
dan stanger
···@evolving.com
From: Barry Margolin
Subject: Re: structure/class assignments
Date: 
Message-ID: <3uf17b$pso@tools.near.net>
In article <··········@teal.csn.net> ······@csn.net (Dan Stanger) writes:
>i have data that is presented to me in a list which i had intended
>to put into a structure.  the structure elements are
>month day year hours minutes dur-hour dur-tenths tgn
>i could also put this into a clos class.
>i then want to store them into a record/class with the following elements.
>month day year hours minutes duration tgn
>where duration = dur-hour*600 + dur-tenths.
>my first structure is l and my second structure is c.  is it possible to
>code this so i dont have to refer to each element of the structure in the
>assignment so i can assign month to month, day to day ... except for
>the duration where i need to execute the above formula for duration?
>or possibly to automaticly generate the assignment code with a macro
>except doing something special for duration?

For structures, you need something like this:

(defmacro copy-slots (source source-prefix dest dest-prefix
                      &rest slot-names)
  (let ((source-var (gensym))
        (dest-var (gensym)))
    (flet ((concat-sym (prefix suffix)
             (intern (concatenate 'string prefix suffix))))
      `(let ((,source-var ,source)
	     (,dest-var ,dest))
	 (setf ,@(loop for slot in slot-names
		    collect (concat-sym dest-prefix slot)
                    collect dest-var
                    collect (concat-sym source-prefix slot)
                    collect source-var))))))

Then you write something like:

(copy-slots l l- c c- month day year hours minutes tgn)

If both the source and destination are CLOS classes you don't need to use a
macro, since you can call SLOT-VALUE in an ordinary function:

(defun copy-clos-slots (source dest &rest slot-names)
  (dolist (slot slot-names)
    (setf (slot-value source slot) (slot-value dest slot))))

(copy-clos-slots l c 'month 'day 'year 'hours 'minutes 'tgn)
-- 
Barry Margolin
BBN Planet Corporation, Cambridge, MA
······@bbnplanet.com
Phone (617) 873-3126 - Fax (617) 873-5124