Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deep copy function #41

Open
gkz opened this issue Dec 30, 2012 · 2 comments
Open

Add deep copy function #41

gkz opened this issue Dec 30, 2012 · 2 comments

Comments

@gkz
Copy link
Owner

gkz commented Dec 30, 2012

create a deep copy of objects/arrays

gkz/LiveScript#224

@joneshf
Copy link

joneshf commented Jul 21, 2013

How would this go? Do you need a deep-copy in both List and Obj, or should there one in index. Reason being, you could have a list with an object, or an object with a list. Both of which should be deep-copy-ed. So it seems like you'd have the exact same function in both, something like:

deep-copy = ->
  match typeof! it
  | (is \Object) => {[k, deep-copy v] for k, v of it}
  | (is \Array)  => [deep-copy i for i in it]
  | otherwise    => it

Are there other types I'm forgetting?

@anko
Copy link

anko commented Jul 31, 2014

@joneshf Cycles kill it:

a = {}
a.a = a     # self-reference
deep-copy a #=> [ infinite loop ]

Well, without tail-call optimisation, it'll overflow the stack instead.

Deep copy functions have been discussed extensively before and found hard or impossible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants