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

Comments

Projects
None yet
1 participant
@xiaq
Copy link
Member

commented Feb 7, 2016

No description provided.

@xiaq

This comment has been minimized.

Copy link
Member Author

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.

@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

This comment has been minimized.

Copy link
Member Author

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.

@xiaq

This comment has been minimized.

Copy link
Member Author

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.)

@xiaq xiaq modified the milestones: 1.0, 0.10 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
You can’t perform that action at this time.