|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- # Functions return their last expression
- func := {
- "hello"
- }
-
- # Call a function without arguments using ()
- print func()
-
- # A function, returning a function, with a closure so that it can access
- # variables from outside
- str := "Hello World"
- func := {
- {
- str
- }
- }
-
- # func() returns a function, which can be called again with an extra ()
- print func()()
-
- func := {
- {
- # $ is a variable containing the arguments passed to the function,
- # so this nested function sets the global 'str' variable to whatever
- # the function is passed
- str = $.0
- }
- }
-
- # func() calls the 'func' function with no arguemnts, and the nested function
- # is returned. That returned function is then called with 10 as a parameter.
- func() 10
-
- # Since the nested function modified it, 'str' should now be the number 10
- print str
-
- func := {
- # Variables don't have to be global; this function returns a function which
- # has a reference to the 'retval' variable
- retval := "what's up"
- {retval}
- }
- print func()()
-
- # Lastly, just print a function literal
- print {0}
|