-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add @stack which stacks multiple structs into one. Closes #4 #5
base: master
Are you sure you want to change the base?
Conversation
Hmm, that |
Alright, |
Not sure about the AppVeyor error though, I have no idea about Windows stuff. |
I am currently trying to get something like |
This is cool. Does it handle type parameters on Also maybe |
Yes I was unsure about the naming, I thought stacks is ok as reference to stacking cups, but no idea 🙈 Here are some ideas:
Type parameters work like this (I will add tests): julia> using Mixers, Parameters
julia> struct Foo
x::Int32
end
julia> struct Bar
y::Int64
end
julia> struct Fjoord{T}
z::T
end
julia> @stack Narf{T} Foo Bar Fjoord
julia> Narf{Bool}(1, 2, true)
Narf{Bool}(1, 2, true)
julia> fieldtypes(Narf)
(Int32, Int64, Any)
julia> typeof(Narf{Bool}(1, 2, true))
Narf{Bool} I however could not get julia> using Mixers, Parameters
julia> struct Foo
x::Int32
end
julia> struct Bar
y::Int64
end
julia> @with_kw @stack Baz Foo Bar
ERROR: LoadError: Only works on type-defs or named tuples.
Make sure to have a space after `@with_kw`, e.g. `@with_kw (a=1,)
Also, make sure to use a trailing comma for single-field NamedTuples. |
Oh right sorry I missed that - the outer macro runs first! The trick is to put that macro inside the Try reusing those methods if possible. Also for consistency with Narf{T} But the brackets should stay - it marks the paramtric type and sets up the AST to insert |
Also thinking about it I'm not sure how you can get But allowing macros would allow you to apply some |
Sorry for the late response! I am working on it but it's really tricky, especially that I don't have much experience with macros ;) I'll report back when I got something... |
The
@stack
macro concatenates the types of the given structs and creates a new one.Let me know what you think about this. It directly defines the structs, maybe you want it to provide a "template" as an intermediate step first, as proposed in #4 ?