HuoLanguage / huo

interpreted language written in C
MIT License
212 stars 21 forks source link

Recursive arrays #25

Open TheLoneWolfling opened 8 years ago

TheLoneWolfling commented 8 years ago

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:

Should this be forbidden, or should this be supported?

incrediblesound commented 8 years ago

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

(let r [ r ] )

is that correct?

TheLoneWolfling commented 8 years ago

Yep.

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

TheLoneWolfling commented 8 years ago

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 commented 8 years ago

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?