Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -1,23 +1,27 @@
|
|||
local :no-copy set{ :num :str :ident :pair :frac :func }
|
||||
local :(copy-action) {}
|
||||
|
||||
(copy-action)!list obj cache:
|
||||
local :new []
|
||||
set-to cache obj new
|
||||
for i range 0 -- len obj:
|
||||
push-to new (deepcopy) @obj! i cache
|
||||
return new
|
||||
|
||||
(copy-action)!dict obj cache:
|
||||
local :new {}
|
||||
set-to cache obj new
|
||||
for key in keys obj:
|
||||
set-to new (deepcopy) @key cache (deepcopy) @obj! @key cache
|
||||
return new
|
||||
|
||||
labda obj cache:
|
||||
set-to cache @obj dup copy @obj
|
||||
set-default (copy-action)
|
||||
|
||||
(deepcopy) obj cache:
|
||||
if has cache obj:
|
||||
return get-from cache obj
|
||||
if has no-copy type obj:
|
||||
# this object is either immutable
|
||||
# or a function object which can't be copied
|
||||
return obj
|
||||
if = :list type obj:
|
||||
local :new []
|
||||
set-to cache obj new
|
||||
for value in reversed copy obj:
|
||||
push-to new (deepcopy) value cache
|
||||
return new
|
||||
else:
|
||||
local :new {}
|
||||
set-to cache obj new
|
||||
for key in keys obj:
|
||||
set-to new (deepcopy) key cache (deepcopy) get-from obj key cache
|
||||
return new
|
||||
return @cache! @obj
|
||||
(copy-action)! type @obj @obj cache
|
||||
|
||||
deepcopy obj:
|
||||
(deepcopy) obj {}
|
||||
|
|
@ -27,30 +31,22 @@ deepcopy obj:
|
|||
set :A { :foo [ "bar" ] [] [ & 1 2 & 3 4 ] }
|
||||
set :B deepcopy A
|
||||
|
||||
. A
|
||||
#prints: { [ ] [ & 1 2 & 3 4 ] :foo [ "bar" ] }
|
||||
. B
|
||||
#prints: { [ ] [ & 1 2 & 3 4 ] :foo [ "bar" ] }
|
||||
!. A
|
||||
!. B
|
||||
|
||||
push-to get-from B :foo "HODOR"
|
||||
|
||||
. A
|
||||
#prints: { [ ] [ & 1 2 & 3 4 ] :foo [ "bar" ] }
|
||||
. B
|
||||
#prints: { [ ] [ & 1 2 & 3 4 ] :foo [ "bar" "HODOR" ] }
|
||||
!. A
|
||||
!. B
|
||||
|
||||
#it works with cycles:
|
||||
set :C push-through dup []
|
||||
set :D deepcopy C
|
||||
|
||||
. C
|
||||
#prints: [ [ [ [ [...] ] ] ] ]
|
||||
. D
|
||||
#prints: [ [ [ [ [...] ] ] ] ]
|
||||
!. C
|
||||
!. D
|
||||
|
||||
push-to C 7
|
||||
|
||||
. C
|
||||
#prints: [ [ [ [ [...] 7 ] 7 ] 7 ] 7 ]
|
||||
. D
|
||||
#prints: [ [ [ [ [...] ] ] ] ]
|
||||
!. C
|
||||
!. D
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue