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

Simplify macro rewriters and avoid some prospective bugs #238

Open
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@thautwarm
Copy link

thautwarm commented Feb 3, 2019

You may want to check this clean implementation of @select:
https://github.com/thautwarm/Query.jl/blob/34f6dbaf5aba156fafa9d60335126a7795f6b676/src/table_query_macros.jl#L49

macro select(args...)
    foldl(args, init=NamedTuple()) do prev, arg
        @match arg begin
            :(everywhere()) => :_

            ::Int && if arg > 0 end =>
                :( merge($prev, QueryOperators.NamedTupleUtilities.select(_, Val(keys(_)[$arg]))) )

            ::Int && if arg < 0 end =>
                let sel = ifelse(prev == NamedTuple(), :_, prev)
                    :( QueryOperators.NamedTupleUtilities.remove($sel, Val(keys($sel)[-$arg])) )
                end
            ::QuoteNode =>
                :( merge($prev, QueryOperators.NamedTupleUtilities.select(_, Val($(arg)))) )
     ...
end

Also, there're some prospective bugs that've been avoided, e.g., quoted " in fieldname of dataframes.

df |> @select(startwith("\"a\""))
@thautwarm

This comment has been minimized.

Copy link
Author

thautwarm commented Feb 3, 2019

I have no idea about the compatibility issues when Julia version is lower than v1.0 :(

@davidanthoff

This comment has been minimized.

Copy link
Member

davidanthoff commented Feb 3, 2019

I have no idea about the compatibility issues when Julia version is lower than v1.0 :(

I'll look through the rest of the PR when I have bit more time, but just a quick response on this: I think we could probably drop julia 0.7 support at this point. I think we should keep 1.0 support, given that that is the long term supported version of julia.

@thautwarm

This comment has been minimized.

Copy link
Author

thautwarm commented Feb 4, 2019

Perfect, I'd like to continue refactoring those macro rewriters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment