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

Elegant rule for what to copy

Here's an elegant rule for what to recursively copy and what to stop at
when doing a recusive copy operation. Stop at anything that has an interned
name (whereby READing in that name will give that same object) and recurse
through anything else. The idea is that copying a structure will be the
same as PRIN1ing it out and READing it back in but more efficient.
Thus a named array (does CL have them?) will be a stop point, wheras an
anonymous array will be recursed through. Interned symbols (IDs) will be
stop points, but GENSYMs will be recursed through, with another GENSYM of
exactly the same name replacing it, and with copies of the value and plist
and function. (In that case READing it back in would accidently INTERN all
the former GENSYMs, so COPY is more "right" than PRIN1-READ.)
There's a slight problem for numbers, where you're supposed to recurse through
them but there's nothing much to recurse through, so the elegant rule does
have a little deficiency there.
Of course for circular structure and to-be-preserved shared structure we
have an alternate more expensive printing routine and likewise should have
a more expensive copy routine.