Giter Site home page Giter Site logo

Comments (8)

munificent avatar munificent commented on July 28, 2024

Oh, good catch. I was aware of this but, like you, felt like it was too much of chore it implement correctly. Or, at least, I felt it was too much of a chore right now. There are certainly more important things to work on right now. :)

Fixing it correctly isn't too hard, actually. You just have to keep a list of the lists you've already visited, and if you encounter a list that's been visited already, just print "..." instead of recursing into it. If you'd like to take a stab at it, you'd just need to:

  1. Write a little test case.
  2. Fix it in corelib.wren.
  3. Run make_corelib to slurp that code into wren_core.c.
  4. Make sure the test passes. :)

If not, I'll get around to fixing it eventually.

from wren.

 avatar commented on July 28, 2024

You just have to keep a list of the lists you've already visited, and if you encounter a list that's been visited already, just print "..." instead of recursing into it.

Is this needed? I think the recursion only happens when a list contains itself. Is it sufficient to only check for this?

from wren.

kmarekspartz avatar kmarekspartz commented on July 28, 2024

What if it contains a list which contains itself?

var x = []
var y = []
y.add(y)
x.add(y)
IO.print(x)

from wren.

munificent avatar munificent commented on July 28, 2024

@zeckalpha is right. To be fully general, you have to handle deeper cycles too.

from wren.

kmarekspartz avatar kmarekspartz commented on July 28, 2024

Now that I've got the concat operator, I did some work on handling toString for recursive lists:

https://github.com/zeckalpha/wren/compare/feature;toString-circular-lists

from wren.

kmarekspartz avatar kmarekspartz commented on July 28, 2024

I've done a bit more on that branch, moving the extraneous helpers in as functions inside List.toString. Still not sure this is the right approach, and untested.

from wren.

kmarekspartz avatar kmarekspartz commented on July 28, 2024

Should that branch be ported to C and/or updated to reflect the split of List into List and Sequence?

from wren.

munificent avatar munificent commented on July 28, 2024

You won't be able to port it to C since it contains calls to toString. Right now, primitive methods cannot call user-defined ones.

Let's just sit on this for now. I might take a stab at it later. Either way, it's not a very big issue.

from wren.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.