-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added support for named parameters.
Example: func foo(a, b, c) { say a; # prints: 1 say b; # prints: 2 say c; # prints: 3 } foo(b: 2, c: 3, a: 1); - Default values of parameters of functions and methods can now default to previous declared arguments. Example: func test(a=1, b=a+2) { say a; # prints: 1 say b; # prints: 3 (the result of a+2) } test();
- Loading branch information
trizen
committed
Oct 23, 2015
1 parent
2827b5e
commit 8097b21
Showing
11 changed files
with
247 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package Sidef::Variable::NamedParam { | ||
|
||
sub new { | ||
my (undef, $name, @args) = @_; | ||
bless [$name, \@args], __PACKAGE__; | ||
} | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/ruby | ||
|
||
# | ||
## Default values for function and method parameters | ||
# | ||
|
||
# | ||
## Test 1 | ||
# | ||
|
||
func test1(a, b, c=a+b, d=c+b) { | ||
assert_eq(c, a+b); | ||
assert_eq(d, c+b); | ||
} | ||
|
||
test1(1, 2); | ||
test1(1, 2, 3, 5); | ||
test1(42, 99); | ||
|
||
# | ||
## Test 2 | ||
# | ||
|
||
func test2(a, b=(a+42), c=21+a+b) { | ||
assert_eq(b, a+42); | ||
assert_eq(c, 21+a+b); | ||
} | ||
|
||
test2(100); | ||
test2(100, 100+42, 100+100+42+21); | ||
|
||
# | ||
## Test 3 | ||
# | ||
|
||
func test3(a, b: 21, c=42) { | ||
assert_eq(b, 21); | ||
assert_eq(c, 42); | ||
assert_eq(a, 13) if defined(a); | ||
} | ||
|
||
test3(); | ||
test3(b: 21); | ||
test3(a: 13); | ||
test3(13); | ||
|
||
|
||
say "** Test passed!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.