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

match dot expression #25

Closed
thautwarm opened this issue Jan 21, 2019 · 2 comments
Closed

match dot expression #25

thautwarm opened this issue Jan 21, 2019 · 2 comments
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@thautwarm
Copy link
Owner

thautwarm commented Jan 21, 2019

JuliaLang/julia#6104 (comment)

There is a problem that QuoteNode would be automatically evaluated, so when source ast contains QuoteNode, pattern matching compilation generates the same QuoteNode and inserts it into the generated ast. The QuoteNode generated by pattern compilation would then be auto evaluated and finally we got a a != QuoteNode(a), in another words, matching fails.

To solve this problem we introduce a QuotePattern to avoid auto evaluation of QuoteNode generated by patterns.

Following the knowledge given by the the first referenced issue, this technically works.

@thautwarm thautwarm added enhancement New feature or request bug Something isn't working labels Jan 21, 2019
@thautwarm thautwarm added this to the 0.2.0 milestone Jan 21, 2019
@thautwarm
Copy link
Owner Author

Now we can write this:

using MLStyle

module Linq
    select(arr, f) = map(f, arr)
end

macro linq(expr)
    @match expr begin
        :($subject.$method($(args...))) =>
            let method = getfield(Linq, method)
                quote $method($subject, $(args...)) end
            end
        _ => @error "invalid"
    end
end

@assert (@linq [1, 2, 3].select(x -> x * 5)) == [5, 10,  15]

@thautwarm
Copy link
Owner Author

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant