Multiple distinct objects: Difference between revisions
Content added Content deleted
m (Add `{{task}}` to top of page) |
|||
Line 874: | Line 874: | ||
produces <code>$n</code> distinct objects. |
produces <code>$n</code> distinct objects. |
||
=={{header|Phix}}== |
|||
Phix uses shared reference counts with copy-on-write semantics. Creating n references to the same mutable object is in fact the norm, |
|||
but does not cause any of the issues implicitly feared in the task description. In fact, it is not possible to create shared references |
|||
such that when one is updated they all are, except by deliberately storing an index to another table that stores the objects, rather |
|||
than the object itself. Also, apart from low-level trickery and interfacing to shared libraries, there are no pointers to normal hll objects. Finally, sequences need not be homogeneous. |
|||
<lang Phix>sequence s = repeat("x",3*rand(3)) |
|||
?s |
|||
s[rand(length(s))] = 5 |
|||
?s |
|||
s[rand(length(s))] &= 'y' |
|||
?s |
|||
s[rand(length(s))] = s |
|||
?s</lang> |
|||
{{out}} |
|||
<pre> |
|||
{"x","x","x","x","x","x"} |
|||
{"x","x","x","x","x",5} |
|||
{"xy","x","x","x","x",5} |
|||
{"xy",{"xy","x","x","x","x",5},"x","x","x",5} |
|||
</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |