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

Is it possible to define a native function with a default argument? #751

Open
suzuki-shunsuke opened this issue May 31, 2024 · 0 comments
Open

Comments

@suzuki-shunsuke
Copy link
Contributor

Jsonnet's function supports default argument.

https://jsonnet.org/learning/tutorial.html#functions

e.g.

// Default arguments are like Python:
local my_function(x, y=10) = x + y;

https://pkg.go.dev/github.com/google/[email protected]#NativeFunction

NativeFunction has a field Params, which a list of Identifier.
Identifier represents a variable / parameter / field name. +gen set.

https://pkg.go.dev/github.com/google/[email protected]/ast#Identifier

I want to define a default argument, but is it possible?

I tried to add a default argument named opts, but it didn't work.

Params: ast.Identifiers{"pattern", "s", "opts"},

If I omit the argument, the error RUNTIME ERROR: Missing argument: opts occurred.

I tried the following code, but it also didn't work. RUNTIME ERROR: Missing argument: opts={}

Params: ast.Identifiers{"pattern", "s", "opts={}"},
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