Rosetta code

39 views
Skip to first unread message

The Beez

unread,
Mar 25, 2013, 6:14:11 PM3/25/13
to 4tH-compiler
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

The Beez

unread,
Mar 26, 2013, 1:52:14 PM3/26/13
to 4th-co...@googlegroups.com


On Monday, March 25, 2013 11:14:11 PM UTC+1, The Beez wrote:
I added a few more OO examples. Now we're the Forth compiler with most OO examples in Rosetta code!
It started off because I wanted to see how solid this implementation was - I'm pretty convinced now we're quite good, believe me ;-)

Fun thing is: I don't even LIKE OO programming to start with - as you might know.

And BTW: I fixed a tiny bug in the assertions code that must have been there for ages. I assume you guys aren't using it that much ;-)

Hans Bezemer
Reply all
Reply to author
Forward
0 new messages