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

Create Parameter type without specifying a name #17

Closed
ChrisRackauckas opened this issue Sep 14, 2016 · 6 comments
Closed

Create Parameter type without specifying a name #17

ChrisRackauckas opened this issue Sep 14, 2016 · 6 comments

Comments

@ChrisRackauckas
Copy link
Collaborator

It would be nice to be able to do:

p = @with_kw type # could also be immutable
    a::Int = 6
    b::Float64 = -1.1
    c::UInt8
end

and have it silently create a parameter type and return and instance of that type. The tool for doing this is described here: http://stackoverflow.com/questions/39485715/julia-design-silently-defining-naming-types-in-macros/39493415?noredirect=1#comment66311481_39493415. This could be helpful when all you care about is getting a type for its fields, but don't plan on making it again (and it's easier than coming up with arbitrary names all the time).

@mauro3
Copy link
Owner

mauro3 commented Sep 15, 2016

I guess that would be a poor man's named tuple. See https://github.com/blackrock/NamedTuples.jl, JuliaLang/julia#16580. Could be useful. But you're example would error as c does not have a (default) value, right?

@ChrisRackauckas
Copy link
Collaborator Author

Yeah, I assume it would error without a default.

@ChrisRackauckas
Copy link
Collaborator Author

NamedTuples are immutable like tuples, right? That would make the "anonymous immutable" the same, but the "anonymous type" would be different.

@ChrisRackauckas
Copy link
Collaborator Author

Maybe a struct like in JuliaLang/julia#16580 is really the right thing for my application.

@mauro3
Copy link
Owner

mauro3 commented Sep 15, 2016

Yep JuliaLang/julia#16580 will be well cool to have.

Well, I don't have a use for this but would accept a PR (if it doesn't add too much complexity).

@ChrisRackauckas
Copy link
Collaborator Author

Closing this because the struct would be a better idea.

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