On Nov 22, 5:02 pm, "Pascal J. Bourguignon" <
p...@informatimago.com>
wrote:
> Nicolas Edel <
nicolas.e...@gmail.com> writes:
> > (defstruct foo
> > (slot1)
> > (slot2)
> > (slot3))
>
> > (defvar i0 (make-foo ...))
> > (defvar i1 (make-foo ...))
>
> > Now Suppose I want to merge i1 into i0 using the following rule:
> > for each slot of i0
> > do
> > if slot is null
> > then
> > slot of i0 := slot of i1
> > end
> > end
>
> > Is there a way to iterate on a struct slots ?
>
> Yes.
>
> > I did it
>
> So you already knew there was a way.
>
Yes, but not using any generic scheme.
I did something like this:
(defun merge-foo (var0 var1)
(macrolet ((merge-slot (slot var0 var1)
(let ((slot-name (intern (concatenate 'string
"FOO-" (symbol-name slot)))))
`(when (null (,slot-name ,var0))
(setf (,slot-name ,var0) (,slot-
name ,var1)))))
(merge-slots (var0 var1)
`(progn
(merge-slot slot1 ,var0 ,var1)
(merge-slot slot2 ,var0 ,var1)
(merge-slot slot3 ,var0 ,var1))))
(merge-slots var0 var1)
var0))
> Did you want to do it only for FOO structures?
No: I have 3 different structures. The reason I'd like to avoid code
duplication.
> If not, did you consider inherited structures ("included" structures)?
> A FOO is not necessary just a FOO...
No, I didn't. But what else could be a FOO ?
:Nicolas