Copy a string: Difference between revisions

Added Bracmat
(→‎Using only standard facilities: commented out disproportionallly large irrelevant text. I think it should be removed.)
(Added Bracmat)
Line 83:
?(^same$+5) = ?(^source$+5)
PRINT same$</lang>
 
=={{header|Bracmat}}==
Because in Bracmat strings are unalterable, you never want to copy a string. Still, you will obtain a copy of a string by overflowing the reference counter of the string. (Currently, reference counters on strings and on most operators are 10 bits wide. The <code>=</code> operator has a much wider 'inexhaustible' reference counter, because it anchors alterable objects.) Still, you won't be able to test whether you got the original or a copy other than by looking at overall memory usage of the Bracmat program at the OS-level or by closely timing comparison operations. You obtain a new reference to a string or a copy of the string by simple assignment using the <code>=</code> or the <code>:</code> operator:
<lang>abcdef:?a;
!a:?b;
 
c=abcdef;
!c:?d;
 
!a:!b { variables a and b are the same and probably referencing the same string }
!a:!d { variables a and d are also the same but not referencing the same string }
</lang>
 
=={{header|C}}==
483

edits