-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pony JSON - difficult to modify iso
JsonDoc
#16
Comments
In terms of naming, we could go with: Another option that may work well is |
This introduces a viewpoint for accessing the internal data for a JSON element: document, object, array. This simplifies the process for modifying `iso` instances of `JsonDoc` after prior creation. ponylang/ponyc#3922
I've started putting together the following PR: which allows one the write the following: be dostuff(jdoc: JsonDoc iso) =>
_seq = _seq + 1 // update the sequence
let jdoc': JsonDoc iso = recover
let jdoc_ref = consume ref jdoc
try
let m: Map[String, JsonType] ref = (jdoc_ref() as JsonObject)()
m("seq") = _seq.i64()
end
jdoc_ref
end |
This demonstrates that we can access the internal `data` fields in an `iso` document, make modifications and recover an `iso`. ponylang/ponyc#3922
I've started drafting and RFC for this change: I'll send through a PR once I've completed the documentation. |
@sgebbie Cool. One point to consider is that since pony is pre-1.0, we can be more relaxed about breaking changes. In this case, I'd at least write down the option of making the |
Here we demonstrate various combinations of access using the `apply()` sugar or the literal invocation of `apply()`. ponylang/ponyc#3922
This sketches the consideration for adding `apply()` methods to JSON, together with potential alternatives. ponylang/ponyc#3922
This sketches the consideration for adding `apply()` methods to JSON, together with potential alternatives. ponylang/ponyc#3922
I've posted an RFC for this proposed change: |
I'm not going to suggest that we should hold this up for it, but I'm marking this as another use case that is solved very easily by recover blocks with receiver ponylang/rfcs#182 |
Following the Pony sync 2021-11-23 it seems like the issue in the The suggestion was to rather file a new bug report that isolates an example of this difference in behaviour. |
Currently
json.JsonDoc
provides accessors via thedata
field. However, if one has aniso
reference to aJsonDoc
that has already been populated, then it is difficult to modify the data after the fact.Background
For example, the following code will work (where a
ref
alias is recovered):But then
jdoc'
is no longeriso
.One could replace
jdoc.data
altogether:But then the full map would need to be recreated.
Proposal
Based on feedback from Borja o'Cook we could instead introduce "getters" into
JsonDoc
andJsonObject
(andJsonArray
) such that viewpoint adaptation could be applied to help achieve the desired access to thedata
while satisfying the reference capability constraints.The text was updated successfully, but these errors were encountered: