Code Monkey home page Code Monkey logo

Comments (5)

mgreenbe avatar mgreenbe commented on June 19, 2024 1

My reasoning is twofold: A putState parser would make it really simple to port things from (F)Parsec. Second, I'd like userState state to revert if the parser needs to backtrack, and that won't happen automatically if I'm always mutating it in place (right?).

from parjs.

GregRos avatar GregRos commented on June 19, 2024 1

@mgreenbe Interesting! I never really thought about reverting user state. And yeah, you're right, it's probably not possible unless I allow replacing user state in the first place.

Now that I see the reasoning, it's definitely something I'll add. The two techniques can be complementary.

from parjs.

GregRos avatar GregRos commented on June 19, 2024

Nope. It's sort-of by design. In Haskell, there is no way to mutate anything at all, so you have to be able to replace the user state. In F# or similar, you can't just define properties on the state object willy-nilly either, so again you need to have a way to alter it.

In JavaScript though, I think it's not needed and keeping the same user state object throughout the parsing session has advantages. There is no problem of parallelism, since this is totally synchronous JS we're talking about. You need to allocate fewer objects, and there is no problem of erasing data other parsers need to function. It also just seems appealing in terms of API, since that way there is a single, unified method of modifying user state, and you can do it from pretty much any parser/combinator.

If you don't want to add/delete properties from the object whenever you want, you can always create a specific property, e.g. immutable, and update only that property with a new object every time. The result is quite similar to a putState parser.

But if you really don't like it, I can just add it in. Can you explain why it's important to you?

from parjs.

mgreenbe avatar mgreenbe commented on June 19, 2024

Thanks! This will be a big help to me.

from parjs.

GregRos avatar GregRos commented on June 19, 2024

Now there is a replaceState combinator that fulfills this role. It replaces the state in the context of the parser you're applying it to.

from parjs.

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.