diff options
Diffstat (limited to 'examples/all-examples.txt')
| -rw-r--r-- | examples/all-examples.txt | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/examples/all-examples.txt b/examples/all-examples.txt index 6e02967..f1a81b8 100644 --- a/examples/all-examples.txt +++ b/examples/all-examples.txt @@ -205,13 +205,13 @@ ifnot pid { # Test: function named arguments, explicit ret, and multiple return values # zero-arg function with explicit return -func answer() { +fun answer() { ret 42; } assert 42 == say answer(); # single-arg function — factorial with a while loop and ret -func factorial(n) { +fun factorial(n) { my result = 1; while n > 1 { result = result * n; @@ -222,13 +222,13 @@ func factorial(n) { assert 120 == say factorial(5); # two-arg function -func add(a, b) { +fun add(a, b) { ret a + b; } assert 8 == say add(3, 5); # conditional return inside if -func absval(n) { +fun absval(n) { if n < 0 { ret neg n; } ret n; } @@ -236,14 +236,14 @@ assert 5 == say absval(5); assert 5 == say absval(neg 5); # multiple return values — both land on the caller's stack -func minmax(a, b) { +fun minmax(a, b) { if a < b { ret a, b; } ret b, a; } say minmax(3, 7); # old-style zero-arg function without parens still works -func greet { +fun greet { say "hello"; } greet; @@ -252,10 +252,10 @@ greet; * Examples of how to use functions *# -func foo { +fun foo { say 1 + a * 3 + b; - func bar { + fun bar { say "Hello i am nested"; } @@ -266,7 +266,7 @@ my a = 2, b = 4; # Create global variables foo; assert 0 == (defined bar); # bar is not available anymore -func baz { +fun baz { say "I am baz"; undef baz; } |
