-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add missing ! to setindex in setting with a lens #71
Conversation
Thanks for the PR. |
My use case was modifing the value in a ref or array.
It is for the modification of immutable objects inside of containers. Equivalent code for current code base.
|
But the pure-ness makes sense, perhaps a |
b2631dd
to
58c9bf2
Compare
I've been thinking about how to support in-place operations in Setfield API. There are two possible semantics:
An interesting consequence is that, when In terms of the (low-level) API, there are two possibilities
The surface syntax for the per-call policy would be relatively easy to implement as we just need to implement entry points that work like The surface syntax for the per-lens policy would be a bit challenging. One possibility is: @set a.(!b).c = value
@set a.(![1]).c = value |
In very early version of
I think to get this started I would prefer the per lens approach. The advantage is that it does not interfer with the current implementation. The disadvantage is that it is probably less dry, as you need to define multiple versions of each lens. As for syntax I think we should start with something simple stupid. We could have
@set!! o.a.b.c.d = x would be equivalent to let l = @lens!!(_.a.b.c.d)
set(o, l, x)
end
|
Any update on this? This functionality would be quite useful for wrapping deeply-nested C structs where the top level struct may or may not be mutable. Happy to help out as well! |
No, I think nothing happened here in this direction. If you want to contribute, that is awesome. I think the hardest decisions are where the mutation is controlled. Quoting @tkf:
I lean towards 2. Maybe @tkf has some opinions on 1. vs 2. or entirely different ideas? |
I took a stab at the per-lens approach and it's not too bad. I'll push the
branch when I'm back at my desk.
If that's the approach we want to go with I'm happy to flesh things out a
bit more. I'm hoping to release a suite of software packages soon and
having the ability to mutate objects would greatly help, so the motivation
is there :)
Colin X Summers
University of Washington
Personal Robotics Lab
www.colinxsummers.com
…On Mon., 7 Oct. 2019, 13:05 Jan Weidner, ***@***.***> wrote:
No, I think nothing happened here in this direction. If you want to
contribute, that is awesome. I think the hardest decisions are where the
mutation is controlled. Quoting @tkf <https://github.com/tkf>:
In terms of the (low-level) API, there are two possibilities
1. Per-call policy: Use one of the three "mutation policies" (i.e., current "always re-construct" plus above two).
2. Per-lens policy: Define (say) `IndexLensMutateIfMutable` and/or `IndexLensTryMutate`.
I lean towards 2. Maybe @tkf <https://github.com/tkf> has some opinions
on 1. vs 2. or entirely different ideas?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#71?email_source=notifications&email_token=AELLS2DJOIWOVD2KBZ5WW43QNOI7HA5CNFSM4IFSYGAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEART65Q#issuecomment-539180918>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AELLS2DD4P5WVLMZVNXKQO3QNOI7HANCNFSM4IFSYGAA>
.
|
@jw3126 Yeah, I think per-lens mutation policy is the way to go. Also, using BangBang.jl for a while, I think try-mutate semantics is more useful than mutate-if-mutable or always-mutate. |
I pushed my quick-and-dirty implementation of the per-lens mutation policy. Hopefully this is along the lines of what you all were thinking! I had to merge #91 because of the circular dependency between BangBangv0.3.1 and Setfield. Initial thoughts? |
Closing, as #92 has more discussion. |
No description provided.