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

Recursive arrays #25

Open
TheLoneWolfling opened this issue Jun 26, 2016 · 4 comments
Open

Recursive arrays #25

TheLoneWolfling opened this issue Jun 26, 2016 · 4 comments

Comments

@TheLoneWolfling
Copy link
Collaborator

This messes all sorts of things up - it's entirely possible to end up with an array that has itself as a member. (Not just as a variable!)

Among the things messed up:

  • Using it as a function parameter will cause a stack overflow.
  • Print will cause a stack overflow.

Should this be forbidden, or should this be supported?

@incrediblesound
Copy link
Member

Wow that's thorny. I'm guessing you're talking about something like:

(let r [ r ] )

is that correct?

@TheLoneWolfling
Copy link
Collaborator Author

Yep.

Or worse, if you somehow end up with value.data.arr[i] == value, not just a variable with a value of value.

@TheLoneWolfling
Copy link
Collaborator Author

Here is one such bug:

(let arr [0, 0, 0, 0, 0])
(each arr item index (map arr item index_b arr))

WARNING: this will run until it gobbles up all memory available, then crash.

@TheLoneWolfling
Copy link
Collaborator Author

Three options as to how to deal with this:

  1. Make "many things" do a full copy of the array. This could be slow.
  2. Ignore it. Add a max depth to array copy / print / etc and bail if it hits the limit.
  3. Make array_copy, print, and a few other things properly handle recursive arrays. This could also be slow, as well as making those functions more complex.

Personally, I'd lean towards 3. Your thoughts?

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

2 participants