-
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
Support indexing involving end #89
Conversation
Do you suggest to use |
I think it's useful only for indexing with Since the part relevant to indexing with |
Yeah, I was wondering about that. |
Exactly. I am not sure if I want to keep maintaining it 😄. That's why it's not registered yet. OTHO, Julia in 1.x may not have drastic changes in AST. It's supposed to be a public API. Also, I need something similar in LazyArrays.jl and probably in BangBang.jl. I don't want to keep (helping) maintaining three different code bases with overlapping functionality. The important question is how overlapping they would be; hence the PRs. |
Actually, how about pulling relevant code from GroundEffects.jl for now? This is a useful feature and I want to use it now that I implemented it :) Whether or not it makes sense to use GroundEffects.jl can be discussed/experimented later. |
l = @lens _[end÷2] | ||
obj = (1,2,3) | ||
@test get(obj, l) == 1 | ||
@test set(obj, l, true) == (true,2,3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some more complicated lenses? Composed and multi index? Also can you add show
tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I added a few more tests. I completed forgot about multi-index version so that's implemented/tested as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. @lens _[end, end]
Regarding struct DynamicIndexLens{F, expr}
f::F
end
DynamicIndexLens(f, expr) = DynamicIndexLens{typeof(f), Symbol(string(expr))}(f)
print_application(io::IO, ::DynamicIndexLens{<:Any, expr}) where {exprr} =
print(io, "[", string(expr), "]") But I don't think it's a good idea to waste compilation time just to get a nice |
Mhh you expect let f = obj -> obj[end]
lens = DynamicIndexLens(f)
Setfield.print_application(io::IO, ::typeof(lens)) = "[end]"
lens
end |
That's an interesting idea. But I guess it doesn't work inside functions? Also, I think it's problematic when the indexing function is a closure shift = 1
lens = @lens _[end - shift] |
I guess it's doable if we handle the lowering of closure:
This feels like the right way to do it but it's rather a non-trivial project for a somewhat auxiliary feature. So, I prefer to do this later (or maybe never unless there is a better idea) if you are OK with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right my show
approach does not work and eval is probably needed. I agree its probably not worth the trouble so lets do this later/never.
Can you maybe add tests that not every indexing is dynamic? E.g. like @test @lens(_[1]) isa IndexLens
? LGTM, feel free to merge.
(Edit: it now does not depend on GroundEffects.jl)
The idea of this PR is to factor out the common logic of lowering AST to an external package: https://github.com/tkf/GroundEffects.jl (still not registered yet)ref: tkf/GroundEffects.jl#1
close #15