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

Support options when defining and calling functions #82

Closed
xiaq opened this issue Feb 7, 2016 · 3 comments
Closed

Support options when defining and calling functions #82

xiaq opened this issue Feb 7, 2016 · 3 comments
Milestone

Comments

@xiaq
Copy link
Member

@xiaq xiaq commented Feb 7, 2016

No description provided.

@xiaq
Copy link
Member Author

@xiaq xiaq commented Mar 10, 2016

Let's reserve the name "argument" for positional arguments and call named arguments "options" instead. Defining and passing options imitate pairs in map literals:

fn f [a b &v]{
    if = `bool $v` $true; then
        println "a = "$a", b ="$b
    else
        println $a$b
    fi
}

f foo bar &v
f foo bar &v=true # equivalent

When defining an option, the value for an option defaults to $false. While when using an option it defaults to $true.

Loading

@xiaq xiaq changed the title Functions should support named arguments Support options when defining and functions Mar 17, 2016
@xiaq xiaq added this to the 1.0 milestone Sep 11, 2016
@xiaq xiaq changed the title Support options when defining and functions Support options when defining and calling functions Sep 14, 2016
@xiaq
Copy link
Member Author

@xiaq xiaq commented Sep 15, 2016

Options are now supported:

{ put $opts[a] } &a=haha # outputs haha

However, it is not yet possible to specify which options are accepted in the function signature -- closures now accept all options and store them in $opts.

Loading

@xiaq
Copy link
Member Author

@xiaq xiaq commented Jul 8, 2017

Slight change in design: Options should have default values:

fn print-ab [a b &verbose=$false]{
    if $verbose; then
        echo "a = "$a", b ="$b
    else
        echo $a$b
    fi
}

print-ab foo bar
print-ab foo bar &verbose=$false # equivalent to above
print-ab foo bar &verbose=$true

(Also updated to reflect syntax change.)

Loading

@xiaq xiaq removed this from the 1.0 milestone Jul 8, 2017
@xiaq xiaq added this to the 0.10 milestone Jul 8, 2017
@xiaq xiaq closed this in 2d6bd1f Aug 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant