ConcreteStructs.jl icon indicating copy to clipboard operation
ConcreteStructs.jl copied to clipboard

Play nicely with other struct def macros

Open jonniedie opened this issue 5 years ago • 12 comments

@concrete should work with Base.@kwdef and similar struct definition macros.

jonniedie avatar Sep 26 '20 12:09 jonniedie

So Base.@kwdef already works with with @concrete

Base.@kwdef @concrete struct Blah
    a
    b
end
julia> blah = Blah(a=1, b="hey")
Blah{Int64,String}(1, "hey")

It doesn't work with the terse keyword, though. Maybe it is going to be better to make a @concrete_terse macro so this isn't a problem. That might just be a good idea anyway. The keyword thing is kinda weird.

jonniedie avatar Oct 03 '20 03:10 jonniedie

I’ll bump myself here because I wanted this again today.

jonniedie avatar Apr 22 '21 23:04 jonniedie

Hopefully dd869e0 does it. Sill doesn't work with the terse keyword, though

jonniedie avatar Aug 30 '21 15:08 jonniedie

Parameters.@with_kw still doesn't work either.

jonniedie avatar Aug 30 '21 15:08 jonniedie

Thank you for making the @concrete macro working with Base.@kwdef. It's very convenient and helpful.

I have independently tried to make ConcreteStructs.jl and Parameters.jl work together well.

My personal conclusion: It is possible to do so by making the following two changes.

  • Change @concrete not creating the inner constructor, so that the Foo{__T_a, __T_b, __T_c}(a, b, c)-type default constructor will be defined.
  • Change Parameters.@with_kw expanding macros in the argument, like Base.@kwdef.

Then @concrete works well with Parameters.@with_kw and more completely with Base.@kwdef.

For details, see my Jupyter notebook.

I am a beginner in programming, so I may be doing something wrong, but I hope it will be helpful.

genkuroki avatar Sep 07 '21 05:09 genkuroki

Thanks for working on this! I'm trying to remember why that inner constructor was there in the first place. I am all for removing it if it's just getting in the way, though. Let me see if I can remember why I have it set up that way.

jonniedie avatar Sep 07 '21 17:09 jonniedie

I implemented something for @concrete to basically commute with any other well-implemented struct def macro by internally shuffling around the order in which the macros are applied.

I'm happy to open a PR so you can have a look. Right now, I don't have the right permissions, though.

janneshb avatar Nov 10 '22 15:11 janneshb

@janneshb ha! I didn’t notice it was you at first. Yeah, a PR would be great if you have it handy. I think you should be able to open one without permissions? I just have to approve the CI to run.

jonniedie avatar Nov 24 '22 18:11 jonniedie

Hm, it shows I can open a PR, but I don't have permission to push to a remote branch on the repo. Which I would need to do to open a PR, right?

janneshb avatar Nov 24 '22 18:11 janneshb

Oh yeah, it'll make you fork your own copy and will be used for the PR.

jonniedie avatar Nov 24 '22 18:11 jonniedie

I implemented something for @concrete to basically commute with any other well-implemented struct def macro by internally shuffling around the order in which the macros are applied.

I'm happy to open a PR so you can have a look. Right now, I don't have the right permissions, though.

Did you ever open that PR? Looks like Parameters' keyword arguments macro doesn't work with @concrete.

ParadaCarleton avatar Jul 01 '23 01:07 ParadaCarleton

I did now. You can check it out here.

janneshb avatar Jul 11 '23 17:07 janneshb