Hi 4tH-ers!
From time to time I'm browsing through Rosetta code, either to nick
some Forth code or add another example. This one was a little
challenge. At first, it looked like a though nut to crack, but after a
few iterations some very neat code came out, that worked like a dream.
It simply implements copying an existing object by this simple scheme:
- The address of an object;
- Convert to the size of the memory allocated;
- Allocate some new memory;
- Since we have the original address, the new one and the size,
copying the contents is easy.
It is so generic, you can use it to copy ANY object, including the
references to other objects. It's neat!
http://rosettacode.org/wiki/Polymorphic_copy#Forth
Hans Bezemer