Polymorphic copy: Difference between revisions
Content added Content deleted
No edit summary |
(Added PicoLisp) |
||
Line 684: | Line 684: | ||
echo $obj4->name(), "\n"; // prints "S" |
echo $obj4->name(), "\n"; // prints "S" |
||
?></lang> |
?></lang> |
||
=={{header|PicoLisp}}== |
|||
Any object can be copied by transferring the value and the property list. |
|||
If we create an object 'A': |
|||
<lang PicoLisp>: (setq A (new '(+Cls1 +Cls2) 'attr1 123 'attr2 def 'attr3 (4 2 0) 'attr4 T)) |
|||
-> $385603635 |
|||
: (show A) |
|||
$385603635 (+Cls1 +Cls2) |
|||
attr4 |
|||
attr3 (4 2 0) |
|||
attr2 def |
|||
attr1 123 |
|||
-> $385603635</lang> |
|||
Then we can easily copy it to a new object 'B': |
|||
<lang PicoLisp>(putl (setq B (new (val A))) (getl A))</lang> |
|||
Inspecting 'B': |
|||
<lang PicoLisp>: (show B) |
|||
$385346595 (+Cls1 +Cls2) |
|||
attr1 123 |
|||
attr2 def |
|||
attr3 (4 2 0) |
|||
attr4 |
|||
-> $385346595</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |