...
Code Block | ||
---|---|---|
| ||
# function that takes no arguments function always_return_5 () return 5 end always_return_5 five = always_return_5() # 5 # function that takes an argument and does no type-checking function add_10_untyped (a) return a+10 end add_10_untyped b = add_10_untyped(4) # 14 # function that takes two arguments function add_two_untyped (a, b) return a+b end add_two_untyped b = add_two_untyped(9, 11) # 20 # function that takes an argument that must be a number function add_10_to_number (a:number) return a+10 end add_10_to_number b = add_10_to_number(6) # 16 b = add_10_to_number('Hello') # Run-time error # function that returns a list of four values function return_4_values_as_list(a) return [a+4, a+3, a+2, a+1] end return_4_values b = return_4_values_as_list(10) # [14,13,12,11] # return four values as named elements of a structure function return_4_values_as_definition(a) return (w: a+1, x: a+2, y:a+3, z:a+20) end return_4_values_as_definition b = return_4_values_as_definition(10) # (w:11,x:12,y:13,z:30) # function that takes any number of arguments function print_all_params loop arg in arguments() print(arg) end loop end print_all_params print_all_params(5, 6, 7, 'Hello') |
Loops, tests & functions
Please check this handout: macrotut_syntax.pdf
Macro tutorial
To learn more about the Macro syntax, please follow the Metview Tutorials.