Copy a string: Difference between revisions
Content deleted Content added
m ab sort + lang tag |
the "Lisp" example was a Common Lisp example; merging and expanding |
||
Line 176: | Line 176: | ||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
<lang lisp>(setq dst (copy-seq src))</lang> |
|||
<lang lisp>(let* ((s1 "Hello") ; s1 is a variable containing a string |
|||
(s1-ref s1) ; another variable with the same value |
|||
(s2 (copy-seq s1))) ; s2 has a distinct string object with the same contents |
|||
(assert (eq s1 s1-ref)) ; same object |
|||
(assert (not (eq s1 s2))) ; different object |
|||
(assert (equal s1 s2)) ; same contents |
|||
(fill s2 #\!) ; overwrite s2 |
|||
(princ s1) |
|||
(princ s2)) ; will print "Hello!!!!!"</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
Line 261: | Line 271: | ||
var dst = '' + src; |
var dst = '' + src; |
||
=={{header|Lisp}}== |
|||
(setf orig "Hello") |
|||
(setf copied (copy-seq orig)) |
|||
test the copy: |
|||
(equalp orig copied) |
|||
t |
|||
(eq orig copied) |
|||
nil |
|||
=={{header|Logo}}== |
=={{header|Logo}}== |