I still am not totally clear about when to use the 'copy' function. In the following sample, I call a function that returns a string, and I want to save that string for future use. I do that operation with, and without, a 'copy' and get the same result. Are my results really the same, or is there something else behind the scenes that makes them actually different even if they look the same?
Thank you. Sample follows, and results follow that.
R E B O L [
]
GLB-SUBSTRING: func [
'Return a substring from the start position to the end position'
INPUT-STRING [series!] 'Full input string'
START-POS [number!] 'Starting position of substring'
END-POS [number!] 'Ending position of substring'
] [
if END-POS = -1 [END-POS: length? INPUT-STRING]
return skip (copy/part INPUT-STRING END-POS) (START-POS - 1)
]
TESTSTRING: 'AAAAAAAAAABBBBBBBBBB'
SUB1: copy ''
SUB2: copy ''
;; Which way is right, or doesn't it matter in this situation?
SUB1: GLB-SUBSTRING TESTSTRING 1 10 ;; no 'copy'
SUB2: copy GLB-SUBSTRING TESTSTRING 11 20 ;; with 'copy'
print rejoin ['SUB1 = '' SUB1 ''']
print rejoin ['SUB2 = '' SUB2 ''']
halt
Result:
SUB1 = 'AAAAAAAAAA'
SUB2 = 'BBBBBBBBBB'
>>