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

Cannot parse optic _ && true #160

Open
jariji opened this issue Jul 27, 2024 · 2 comments
Open

Cannot parse optic _ && true #160

jariji opened this issue Jul 27, 2024 · 2 comments

Comments

@jariji
Copy link

jariji commented Jul 27, 2024

julia> @o (_ && true)
ERROR: LoadError: ArgumentError: Cannot parse optic _ && true. Lens expressions must start with _, got $(Expr(:escape, :(_ && true))) instead.

What's happening here?

@jw3126
Copy link
Member

jw3126 commented Jul 27, 2024

Note that it works with &:

julia> using Accessors

julia> @o _ & true
(::Base.Fix2{typeof(&), Bool}) (generic function with 1 method)

On the other hand && is not a function, but has special short-circuit semantics.

julia> dump(:(_ && true))
Expr
  head: Symbol &&
  args: Array{Any}((2,))
    1: Symbol _
    2: Bool true

julia> dump(:(_ & true))
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol &
    2: Symbol _
    3: Bool true

I think we could in improve the error message, but I don't think we should produce an optic from this.

@aplavin
Copy link
Member

aplavin commented Jul 29, 2024

Btw, this kind of stuff works with AccessorsExtra – not with constants like true but with actual functions on each side:

julia> using AccessorsExtra

julia> @o _.a && _.b
(@o _.a)  (@o _.b)

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 a pull request may close this issue.

3 participants