I would like to know how can I completely copy one Symbol to another. When I say copy, a refer to UpValues, DownValues, FormatValues.. and so on.
I created this function to do that, but I don't know if it's a good practice.
SetAttributes[copy,HoldFirst];
copy[new_Symbol,org_Symbol]:=Module[{},
ClearAll@new;
UpValues@new=UpValues@org/.org:> new;
DownValues@new=DownValues@org/.org:> new;
FormatValues@new=FormatValues@org/.org:> new;
SetAttributes[new,Attributes[org]];
]
So I can copy some symbol b into a using a~copy~b.
There is a simpler way to do that? Or this approach is ok?
Update
Thanks for all comments. This is the evolution of the function above:
SetAttributes[copy,HoldFirst];
new_~copy~org_:=With[{prop={Attributes,UpValues, OwnValues, DownValues, SubValues, NValues, FormatValues, Messages,Options}},
ClearAll@new;
Set[#@new,#@org/.HoldPattern@org:>new]&~Scan~prop;
]

clonefunction of Leonid around, that does basically this. Don't forget Options, NValues, OwnValues, SubValues, Defaults. And make it HoldAll – Rojo Feb 21 at 3:01orgrefers toorgin its definition, willnewkeep referring toorgor tonew? – Szabolcs Feb 21 at 3:03