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

Make [specific type of code] valid code to be used for metaprogramming (useful in e.g. ModelingToolkit and Catalyst DSLs) #54139

Open
TorkelE opened this issue Apr 18, 2024 · 1 comment

Comments

@TorkelE
Copy link

TorkelE commented Apr 18, 2024

Would it be possible to make

@parameters begin
    p [description="A parameter"]
    d [description="Another parameter"]
end

valid notation so that it can be used in metaprogramming?

In e.g. ModelingToolkit (https://github.com/SciML/ModelingToolkit.jl) one can declare parameters using

@parameters p d

Next, if one wants to add metadata to a parameter, it is added in a square bracket afterwards:

@parameters p [description="A parameter"] d [description="Another parameter"]

However, if the number of parameters gets long, this gets hard to read. Here, there is a begin ... end form (with one parameter on each line):

@parameters begin
    p
    d
end

However, if we now need to add metadata, this is not possible using the same notation as with a single line, as this:

:(@parameters begin
    p [description="A parameter"] 
    d [description="Another parameter"] 
end)

is not valid Julia notation. Instead, a , is added to make things work:

@parameters begin
    p, [description="A parameter"]
    d, [description="Another parameter"]
end

This is still a bit awkward, as the notation in single-line and multi-line declarations are different. Would it be possible to enable

:(@parameters begin
    p [description="A parameter"] 
    d [description="Another parameter"] 
end)

as permitted for metaprogramming? I read someone asking about new notations for metaprogramming on the Slack, and got a reply that adding stuff like this was possible. If this is the case, I think adding this would be useful to a set of packages with a fairly large user base (and if it is not possible, we can definitely manage without!).

Would this be useful, @ChrisRackauckas?

@bvdmitri
Copy link
Contributor

We use somewhat similar construction with the where block, e.g. this should work fine for you:

@parameters begin
    p where { description="A parameter" }
    d where { description="Another parameter" }
end

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