Giter VIP home page Giter VIP logo

Comments (8)

tkocmathla avatar tkocmathla commented on June 3, 2024

I also tested this with clojure 1.8.0 and the problem exists there as well. The stack trace is identical except for line numbers.

from hickory.

davidsantiago avatar davidsantiago commented on June 3, 2024

Hm, yeah, that's gonna do that. The problem is that a protocol is used to convert between different representations of the data. The element node has to first call this protocol function recursively on its children, in order to get the value to add to itself. I will think about this some more, but for right now, I don't see a way to get around this easily.

Typically when parsing a potentially infinitely recursive thing, you could use a stack on the heap and manually manage it, instead of implicitly managing it on the actual stack frames of the functions. But with clojure's immutable data structures, it makes you need to have all the elements in a given data structure already finished before you create the thing that holds them. Maybe there is something we could do with zippers here, or maybe we'd need to go into Java and use mutability for this. I'll need to think about it more.

Let me know if you want to work on this.

from hickory.

tkocmathla avatar tkocmathla commented on June 3, 2024

In 135faba, I replaced the recursive protocol implementation with an iterative one using zippers as you suggested. This passes all the existing unit tests. So far, this is just for hickory, but I think I could easily do the same for hiccup.

What do you think?

from hickory.

tkocmathla avatar tkocmathla commented on June 3, 2024

It looks there are some other areas we'd have to convert from recursive to iterative, like hickory.render/hickory-to-html and maybe the hickory.select/select* fns.

from hickory.

davidsantiago avatar davidsantiago commented on June 3, 2024

Yeah, no doubt. Did you see my comment on your commit?

from hickory.

tkocmathla avatar tkocmathla commented on June 3, 2024

I did, thanks. I'll have a look at integrating back into the protocol this weekend.

from hickory.

tkocmathla avatar tkocmathla commented on June 3, 2024

By the way, I was wrong about needing to change the hickory.select/select* fns; they're already iterative and seem to work fine with this pathological case:

(->> (apply str (repeat 2048 "<font>abc"))
     hickory/parse
     hickory/as-hickory
     (select/select (select/tag :font))
     count)
;;=> 2048

from hickory.

tkocmathla avatar tkocmathla commented on June 3, 2024

I updated #51 with a solution that better preserves the protocol, I think (2d21efa). Let me know what you think.

from hickory.

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.