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

Reflection of function arguments #1106

Open
Timmmm opened this issue Jul 30, 2023 · 0 comments
Open

Reflection of function arguments #1106

Timmmm opened this issue Jul 30, 2023 · 0 comments

Comments

@Timmmm
Copy link

Timmmm commented Jul 30, 2023

Is it possible to use reflection to access function arguments? Ideally I would like to reconstruct a string of jsonnet code that I would use to call the function.

My use case is that I have functions that evaluate to a test definition, and I would like them to include their "name" - i.e. how to rerun the test.

local cpptest(source, build_seed, run_seed) = {
    name: 'cpptest(source="%s",build_seed=%d,run_seed=%d)' % [source, build_seed, run_seed],
    ... information about how to build/run the test ...
};

local pythontest(source, run_seed, disable_asserts) = {
    name: 'pythontest(source="%s",run_seed=%d,disable_asserts=%b)' % [source, run_seed, disable_asserts],
    ... information about how to build/run the test ...
};

[
  cpptest("foo.cpp", 0, 1),
  cpptest("foo.cpp", 0, 2),
  cpptest("bar.cpp", 0, 0),
  pythontest("baz.py", 0, false),
]

I can do it manually but it's tedious. One alternative I thought of was to pass the parameters as an object since there is already reflection for that, but it's not very ergonomic. If there's no way to do this, one nice way might be to provide the function arguments as a special object like $args or something so you can use the existing object reflection functions.

I would say accessing the function name is just nice to have. Not too tedious to add manually.

If I implemented something like this would you accept it?

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

1 participant