Giter Site home page Giter Site logo

Comments (1)

yannham avatar yannham commented on June 10, 2024 1

Thanks for reporting. This is definitely a bug. I think the original design guideline was that only merge could impact recursive fields, and as soon as you use a record as a "normal" dictionary (std.record.{update,remove,insert}), you don't get the recursive behavior (otherwise, you should just use merge instead - although remove can't be emulated with merge, but this is on purpose).

Following this guideline, I believe the right result should be the following:

nickel> std.record.update "a" 2 { a = 1, b = a }
{ a = 2, b = 1, }

nickel> std.record.update "a" 2 { a = 1, b = a } & {}
{ a = 2, b = 1, }

nickel> std.record.remove "a" { a = 1, b = a }
{ b = 1, }

nickel> std.record.remove "a" { a = 1, b = a } & {}
{ b = 1, }

I see two ways to achieve that:

  1. We "freeze" the recursive record before any remove primop. We don't really care about insert: insert alone can't mess with existing dependencies, it's either remove alone or the combination of remove and insert that are problematic. This way, there's no more confusion: prior to a remove, the recursive fixpoint is computed once and then it's just a normal data dictionary like in Python with no more recursive references.
  2. The drawback of the previous solution is that it makes it impossible to override or recompute any other value in the original record after a remove, even if it doesn't have anything to do with the removed value: (std.record.remove "a" {a = 1, b = c, c = 2}) & {c | force = 3} would give {b = 2, c = 3}, which might be surprising. We can freeze only the value of the field that is removed instead, and let other fields keep their recursive/overriding capabilities.

I think 1. is a simpler mental model: you don't have to think about what fields were removed or not, as soon as you use one remove operation, all recursive fields are frozen. 2. is probably more flexible, though.

from nickel.

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.