Coder Social home page Coder Social logo

Implement cycle detection about fipp HOT 5 CLOSED

brandonbloom avatar brandonbloom commented on June 14, 2024
Implement cycle detection

from fipp.

Comments (5)

brandonbloom avatar brandonbloom commented on June 14, 2024

wip: https://github.com/brandonbloom/fipp/tree/control

from fipp.

brandonbloom avatar brandonbloom commented on June 14, 2024

This is useful to prevent the printer from going in to an infinite loop, but cyclic structures are pretty rare for pretty-printed EDN data and recursive (and potentially cyclic) printing is pretty rare for standard JVM toString implementations. I'd entertain a patch for this if were a trivially small perf impact, but I suspect that naive usage of a set won't be fast enough due to deep equality comparisons. Maybe if we could use a visited-check that does object-identity only, it would be fast enough, but then we may exceed the complexity/effort budget for this feature.

from fipp.

cichli avatar cichli commented on June 14, 2024

Even just doing a visited-check would cause problems with seq head retention I think. Unless there's some really clever way of doing this that isn't obvious to me, we can't avoid keeping a reference to the entire coll currently being printed, which might be an infinite lazy sequence.

from fipp.

brandonbloom avatar brandonbloom commented on June 14, 2024

Laziness is interesting here, but there's a simpler problem to consider: Cycles in strict data structures, which can only happy with mutation, eg:

(def a (atom nil))
(do (reset! a a) nil)
(fipp.edn/pprint a)

In this case, the root node is, presumably, already going to be retained unless the only thing you want to do is to print the tree out and discard it. So I think there's no real problem there.

Infinite data structures are already addressed by print-length, so I don't think I care about intra-seq cycles. or anything like that.

The interesting case is lazy seqs, but I'm not even sure I care if they are retained when cycle detection is enabled. As long as it's opt in, it should be fine.

from fipp.

brandonbloom avatar brandonbloom commented on June 14, 2024

Closing as I've never actually wanted this in years of using Fipp. If somebody comes along and provides a robust, tested patch for opting-in to cycle detection that doesn't have much overhead, I'd probably accept it.

from fipp.

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.