Is it possible to define a native function with a default argument?
- Dominant language
- Go
- Stars
- 1.8k
- Forks
- 263
- PR merge metrics
- No merged PRs in 30d
Description
Jsonnet's function supports default argument.
https://jsonnet.org/learning/tutorial.html#functions
e.g.
```jsonnet
// Default arguments are like Python:
local my_function(x, y=10) = x + y;
```
https://pkg.go.dev/github.com/google/go-jsonnet@v0.20.0#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/go-jsonnet@v0.20.0/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.
```go
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={}`
```go
Params: ast.Identifiers{"pattern", "s", "opts={}"},
```
Contributor guide
Assessment
This issue has not been assessed yet.