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

Named Function Arguments with defaults and - Feature Proposal #4507

Open
gotjoshua opened this issue Oct 28, 2017 · 1 comment
Open

Named Function Arguments with defaults and - Feature Proposal #4507

gotjoshua opened this issue Oct 28, 2017 · 1 comment

Comments

@gotjoshua
Copy link

gotjoshua commented Oct 28, 2017

This feature request is continuing a discussion here:
#2645 (comment)

I feel that the current way to define named arguments and give them defaults, could use some improvement, so I offer a proposal here to discuss some possibilities. I'd like it to work as close to ECMA as possible:

11.1.1 Default parameter values

function func(x, y=0) {
    return [x, y];
}
func(1, 2); // [1, 2]
func(1); // [1, 0]
func(); // [undefined, 0]

I know this precise syntax won't work in fish, but perhaps something like this:

function func -a x, y=0
    return [x, y];
end;

I also thought about making required or optional explicit could be handy (and fish could offer automatic errors when the func is called without required params, eg:

function func --argument-required x --argument-optional y=0
    return [x, y];
end;
func 1 2; // [1, 2]
func 1; // [1, 0]
func null 1; // [null,1]  *does fish understand 'null'?
func; // error: argument x is required

Perhaps it could have a short-form like:

function func -ar x -ao y=0
    return [x, y];
end;

-o and -r would be irrelevant if used without -a

I have zero experience with C code, so I doubt it is me to set up a dev and build environment to play with this, but I am very happy to discuss the details of how we may like the feature to function, and to come in contact with the project maintainers. I think Fish Shell seriously rocks, and I'm happy to help make it better.

@gotjoshua
Copy link
Author

centuries later, i see a fair number of reactions on this...

and i must admit i don't know the state of the art.

Is this still a valid request?
or is there a recommended modern fishy way to accomplish the same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants