copy versus copy/deep
[1/6] from: princepawn:lycos at: 28-Aug-2000 7:33
As my example below shows, there does not appear to a difference in handling nested blocks
between copy and copy/deep
>> a: [ 1 2 [ 3 [ 4 5 ] 6 ] 7 8 ]
== [1 2 [3 [4 5] 6] 7 8]
>> b: copy a
== [1 2 [3 [4 5] 6] 7 8]
>> b
== [1 2 [3 [4 5] 6] 7 8]
>> c: copy/deep a
== [1 2 [3 [4 5] 6] 7 8]
>> c
== [1 2 [3 [4 5] 6] 7 8]
>> b
== [1 2 [3 [4 5] 6] 7 8]
>> a
== [1 2 [3 [4 5] 6] 7 8]
[2/6] from: jelinem1:nationwide at: 28-Aug-2000 9:55
In order to see the difference, you have to change something in the "deep"
data:
>> a: [ 1 2 [ 3 [ 4 5 ] 6 ] 7 8 ]
== [1 2 [3 [4 5] 6] 7 8]
>> b: copy a
== [1 2 [3 [4 5] 6] 7 8]
>> c: copy/deep a
== [1 2 [3 [4 5] 6] 7 8]
>> change a/3 9
== [[4 5] 6]
>> a
== [1 2 [9 [4 5] 6] 7 8]
>> b
== [1 2 [9 [4 5] 6] 7 8]
>> c
== [1 2 [3 [4 5] 6] 7 8]
This shows that 'copy/deep did a true copy of the imbedded blocks, where
'copy did not.
- Michael Jelinek
[princepawn--lycos--com] on 08/28/2000 09:33:39 AM
From: [princepawn--lycos--com] on 08/28/2000 09:33 AM
Please respond to [list--rebol--com]
To: [list--rebol--com]
cc:
Subject: [REBOL] copy versus copy/deep
As my example below shows, there does not appear to a difference in
handling nested blocks between copy and copy/deep
>> a: [ 1 2 [ 3 [ 4 5 ] 6 ] 7 8 ]
== [1 2 [3 [4 5] 6] 7 8]
>> b: copy a
== [1 2 [3 [4 5] 6] 7 8]
>> b
== [1 2 [3 [4 5] 6] 7 8]
>> c: copy/deep a
== [1 2 [3 [4 5] 6] 7 8]
>> c
== [1 2 [3 [4 5] 6] 7 8]
>> b
== [1 2 [3 [4 5] 6] 7 8]
>> a
== [1 2 [3 [4 5] 6] 7 8]
[3/6] from: lmecir::geocities::com at: 28-Aug-2000 17:41
Hi,
The difference:
a: [[1]]
b: copy a
c: copy/deep a
change first a 2
probe a
probe b
probe c
Regards
Ladislav
----- Puvodní zpráva -----
Od: <[princepawn--lycos--com]>
Komu: <[list--rebol--com]>
Odesláno: 28. srpna 2000 16:33
Predmet: [REBOL] copy versus copy/deep
[4/6] from: joel:neely:fedex at: 28-Aug-2000 11:32
See what happens, after executing the code from your example, if you
modify a nested sub-block of a. That's the difference.
>> append a/3/2 99
== [4 5 99]
>> a
== [1 2 [3 [4 5 99] 6] 7 8]
>> b
== [1 2 [3 [4 5 99] 6] 7 8]
>> c
== [1 2 [3 [4 5] 6] 7 8]
>>
-jn-
[princepawn--lycos--com] wrote:
> As my example below shows, there does not appear to a difference in handling nested
blocks between copy and copy/deep
> >> a: [ 1 2 [ 3 [ 4 5 ] 6 ] 7 8 ]
<<quoted lines omitted: 14>>
> Get your FREE Email and Voicemail at Lycos Communications at
> http://comm.lycos.com
--
; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677
REBOL [] print to-string debase/64 decompress #{
789C0BCE0BAB4A7176CA48CAB53448740FABF474F3720BCC
B6F4F574CFC888342AC949CE74B50500E1710C0C24000000}
[5/6] from: galtbarber:mailandnews at: 28-Aug-2000 15:07
If you assign multiple references
to the same memory, then there will be a difference.
With copy/deep, you get a separate instance of
everything. Without it, only the reference is used.
It may seem like a subtle point, but one still worth
looking at. Also, if you are storing object references
in your blocks instead of just integer values then you
would see a difference.
>> x: [a b c d]
== [a b c d]
>> b: []
== []
>> insert/only b :x
== []
>> b
== [[a b c d]]
>> c: copy b
== [[a b c d]]
>> d: copy/deep b
== [[a b c d]]
>> remove x
== [b c d]
>> c
== [[b c d]]
>> d
== [[a b c d]]
[6/6] from: anton:globalcenter:au at: 30-Aug-2000 4:35
Hi,
Here is a quick program to demonstrate this within a VID window:
rebol[
title: "Copy vs Copy/Deep"
]
show-all: does [
show [xf yf z1f z2f]
]
lay: layout [
text "click each of the buttons in turn"
across
text "x" xf: field xc: button "x: [1 2 3]" [do xc/text xf/text: x show-all]
return
text "y" yf: field yc: button "y: reduce [x]" [do yc/text yf/text: y
show-all] return
text "z1" z1f: field z1c: button "z1: copy/deep y" [do z1c/text z1f/text: z1
show-all] return
text "z2" z2f: field z2c: button "z2: copy y" [do z2c/text z2f/text: z2
show-all] return
button "remove x" [remove x show-all] text "(remove the first element from x)"
]
view/title lay "copy vs copy/deep"
Anton.
[galtbarber--MailAndNews--com] wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted