Skip to content
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

Remove mutation support #34

Merged
merged 6 commits into from
Aug 15, 2018
Merged

Remove mutation support #34

merged 6 commits into from
Aug 15, 2018

Conversation

jw3126
Copy link
Owner

@jw3126 jw3126 commented Jul 28, 2018

No description provided.

@codecov-io
Copy link

codecov-io commented Jul 28, 2018

Codecov Report

Merging #34 into master will increase coverage by 1.5%.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master     #34     +/-   ##
========================================
+ Coverage   96.09%   97.6%   +1.5%     
========================================
  Files           4       3      -1     
  Lines         205     125     -80     
========================================
- Hits          197     122     -75     
+ Misses          8       3      -5
Impacted Files Coverage Δ
src/sugar.jl 94.11% <100%> (-0.33%) ⬇️
src/settable.jl 98.24% <100%> (-0.15%) ⬇️
src/lens.jl 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e36f82a...837e8c0. Read the comment docs.

@tkf tkf mentioned this pull request Aug 11, 2018
@@ -4,7 +4,7 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add 1.0 too! #35 🎉

@tkf
Copy link
Collaborator

tkf commented Aug 11, 2018

Do you have some release plan? How about doing it after merging this?

FYI using this branch with my package passed its tests https://travis-ci.org/tkf/Bifurcations.jl/builds/414973794 (although my Setfield usage is very basic).

src/lens.jl Outdated

const NNamedTupleLens{N,s} = NamedTuple{s, T} where {T <: NTuple{N, Lens}}
struct MultiPropertyLens{L <: NNamedTupleLens} <: Lens
lenses::L
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use just a tuple of lenses, rather than a named tuple? With a named tuple, you can only support properties, right? (Though maybe that was the intention as you named it MultiPropertyLens?) I mean, I wonder if it makes sense to support "vectorizing" lens of mixed kinds, like this:

obj0 = (a=1, b=2, c=3)
l = @lens(  # this is a made-up syntax
  _.a,      # get/set by property
  _[3],     # get/set by index
)
obj1 = set(l, obj0, (100, 300))
@assert obj1 == (a=100, b=2, c=300)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Motivation was that I had lots of code, which looks like

obj = @set obj.a = a1
obj = @set obj.b = b1
obj = @set obj.c = c1

And the compiler was often unable to make this as fast as some handwritten

obj = Obj(a1,b1,c1, obj.other_fields...)

I like your approach, but I think it is harder for the compiler. I need to play around with it. Anyway this is a separate concern from removing mutation policy. It was a mistake to add it to this branch and I will remove it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree that it's nice to release a simple version now and do some design iteration. For the multi-lens, let's continue discussion and design iteration in #23 (comment)

@@ -69,7 +69,7 @@ end
@testset "Pack" begin
x = Pack([Cat(:Tama, 1), Cat(:Pochi, 2)])

@set! x.animals[2].nlegs = 5
x = @set x.animals[2].nlegs = 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part is not tested since I commented test_quicktypes.jl out in #31 (comment). I suggest to pull #36 first or cherry-pick it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so the mutability tests fail there with Julia 1.0. I guess this PR should go first.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So #37 is failing as expected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is failing because IndexLens does not support Array anymore. I implemented a fix in #40.

Another (non-) solution is to use tuples in test_quicktypes.jl: #39

@jw3126
Copy link
Owner Author

jw3126 commented Aug 14, 2018

Tagging a new release after removing mutation support sounds fine to me!

@tkf tkf mentioned this pull request Aug 14, 2018
tkf and others added 4 commits August 15, 2018 22:06
* Test against Julia 1.0

* Use the default test script

* Fix after_success for Julia 1.0

* Enable tests with QuickTypes

* Use Tuple instead of Vector in test_quicktypes.jl
@jw3126
Copy link
Owner Author

jw3126 commented Aug 15, 2018

@tkf does this look good to you, anything missing?

@tkf
Copy link
Collaborator

tkf commented Aug 15, 2018

Yup, #39 was all what I wanted to add. It's also great that MacroTools stuff goes upstream (congrats!).

I think it's ready to go!

@jw3126 jw3126 merged commit 6d45e8f into master Aug 15, 2018
@jw3126
Copy link
Owner Author

jw3126 commented Aug 15, 2018

I tagged a new release! Thanks for #39!

@cstjean
Copy link

cstjean commented Nov 9, 2018

I didn't follow this package very closely; why was @set! removed?

@jw3126
Copy link
Owner Author

jw3126 commented Nov 9, 2018

My motivation for removing it was, that I did not use it, but it added baggage to each custom lens definition. Do you need it?

@jw3126
Copy link
Owner Author

jw3126 commented Nov 9, 2018

There is some discussion here #32

@cstjean
Copy link

cstjean commented Nov 9, 2018

I haven't tried using this package yet, but I'd like to use it to modify our default configuration. It would be cleaner to write @set! config.thresh = 0.1. In fact, what would be cooler would be

@set! begin
   config.thresh = 0.1
   config.N = 20
end

or

@set! config begin
    thresh = 0.1
    N = 20
end

or @set!(config, thresh=0.1, N=20)

I can write these macros myself on top of Setfield, but it would be nice to have official support.

I don't know if MutationPolicy is relevant. I just want @set! a.b.c = 2 to become a = @set a.b.c = 2. I think I get the general goal you're trying to accomplish with MutationPolicy, but I'm not sure it's worth the added complexity.

@jw3126
Copy link
Owner Author

jw3126 commented Nov 9, 2018

Ah okay MutationPolicy is irrelevant for this. Having a version of @set! that does no mutation sounds fine to me! I would be happy about a PR. We can further discuss syntax then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants