Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Deepcopy/Factor/deepcopy-1.factor
Normal file
26
Task/Deepcopy/Factor/deepcopy-1.factor
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
USING: accessors arrays io kernel named-tuples prettyprint
|
||||
sequences sequences.deep ;
|
||||
|
||||
! Define a simple class
|
||||
TUPLE: foo bar baz ;
|
||||
|
||||
! Allow instances of foo to be modified like an array
|
||||
INSTANCE: foo named-tuple
|
||||
|
||||
! Create a foo object composed of mutable objects
|
||||
V{ 1 2 3 } V{ 4 5 6 } [ clone ] bi@ foo boa
|
||||
|
||||
! create a copy of the reference to the object
|
||||
dup
|
||||
|
||||
! create a deep copy from this copy
|
||||
>array [ clone ] deep-map T{ foo } like
|
||||
|
||||
! print them both
|
||||
"Before modification:" print [ [ . ] bi@ ] 2keep nl
|
||||
|
||||
! modify the deep copy
|
||||
[ -1 suffix! ] change-bar
|
||||
|
||||
! print them both again
|
||||
"After modification:" print [ . ] bi@
|
||||
16
Task/Deepcopy/Factor/deepcopy-2.factor
Normal file
16
Task/Deepcopy/Factor/deepcopy-2.factor
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
! Create a foo object composed of mutable objects
|
||||
V{ 1 2 3 } V{ 4 5 6 } [ clone ] bi@ foo boa
|
||||
|
||||
! create a copy of the reference to the object
|
||||
dup
|
||||
|
||||
! create a deep copy from this copy
|
||||
object>bytes bytes>object
|
||||
|
||||
! print them both
|
||||
"Before modification:" print [ [ . ] bi@ ] 2keep nl
|
||||
|
||||
! modify the deep copy
|
||||
[ -99 suffix! ] change-bar
|
||||
|
||||
"After modification:" print [ . ] bi@
|
||||
Loading…
Add table
Add a link
Reference in a new issue