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

isdefwith quote seems giving incorrect result #204

Open
mmikhasenko opened this issue May 31, 2024 · 3 comments
Open

isdefwith quote seems giving incorrect result #204

mmikhasenko opened this issue May 31, 2024 · 3 comments

Comments

@mmikhasenko
Copy link

mmikhasenko commented May 31, 2024

I need to convert a mathematical function in a string into Julia lambda function.
Just found the package, it seems very useful.

Just stumbled by a very basic example: expr = :(x -> x + 2) is recognized as a function by isdef, while quote x -> x + 2 end is not recognized.

MWE

julia> expr = quote
    x -> x + 2
end

julia> MacroTools.isdef(expr)
false

julia> eval(expr)(3)
5

julia v1.10
MacroTools v0.5.13

@cstjean
Copy link
Collaborator

cstjean commented Jun 3, 2024

Ah, that's slightly awkward. On one hand, we could do striplines here (and/or remove the begin block) and it would work fine. On the other hand, expr is technically a block that contains a function definition; not a function definition.

I would lean towards lining up the behaviour with splitdef. Does splitdef(expr) work?

@mmikhasenko
Copy link
Author

yes, splitdef works. It correctly identifies the body and args

@cstjean
Copy link
Collaborator

cstjean commented Jun 3, 2024

Then let's fix isdef! Thank you for the bug report. I think it's basically just to remove the block. There's already a function for it in utils.jl IIRC

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

No branches or pull requests

2 participants