Parametric polymorphism: Difference between revisions
m
Sorry I meant C# not C++!
m (Sorry I meant C# not C++!) |
|||
Line 717:
{5,6,7,"apples","oranges"}
</pre>
For comparison
Note that tmap has to be a function rather than a procedure with a reference parameter, but this still achieves
pass-by-reference/in-situ updates, mainly because root is a local rather than global/static, and is the target
of (aka assigned to/overwritten on return from) the top-level tmap() call, and yet it would also manage the
C
tree, just by changing that
<lang Phix>enum data, left, right
Line 742 ⟶ 741:
object root = newnode(1.00)
-- Add some nodes.
root[left] = newnode(1.10)
root[left][left] = newnode(1.11)
root[left][right] = newnode(1.12)
root[right] = newnode(1.20)
root[right][left] = newnode(1.21)
root[right][right] = newnode(1.22)
-- Now the tree has seven nodes.
-- Show
ppOpt({pp_Nest,2})
pp(root)
-- Modify
root = tmap(root,routine_id("add10"))
-- Show
pp(root)
end procedure
|