Comments (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:
- We "freeze" the recursive record before any
remove
primop. We don't really care aboutinsert
: 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 aremove
, the recursive fixpoint is computed once and then it's just a normal data dictionary like in Python with no more recursive references. - 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)
- [LSP] Support import path includes in the lsp
- Some sub-expressions of thunks are re-evaluated several times
- Add support for hexadecimal, octal and binary notation HOT 2
- README is missing Plk in the comparison table. HOT 1
- `std.array.split_at` broken if index equals length of array HOT 2
- Infinite loop (and memory usage) HOT 4
- `{a : "str"}` evaluates into a function HOT 2
- Typo on the homepage (underscore and dash) HOT 4
- Querying in REPL is broken in 1.4 (undue unbound identifier error)
- The LSP doesn't show the details of type errors anymore in the diagnostics HOT 1
- Nickel Release 1.5.0 does NOT contain binaries HOT 3
- Subcommand for applying functions to commandline arguments HOT 4
- Dynamic import resolution HOT 5
- `std.string.find_all` HOT 1
- Add `record.has_field_all` and `record.fields_all` HOT 1
- Add raw strings
- NLS crashes on recursive definitions HOT 11
- Proposal: freeze recursive records upon insert/remove/update/map
- NLS reports same diagnostic message multiple times HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nickel.