Function Arguments

Information may be passed to functions via the argument list, which is a comma-delimited list of variables and/or constants.

ChaosPro supports passing arguments by value (the default) and passing by reference. The number of arguments and the type of each argument must exactly match when calling a function. ChaosPro won’t do any conversion, so ChaosPro won’t have ambiguous function calls.

Making arguments be passed by reference

By default, function arguments are passed by value (so that if you change the value of the argument within the function, it does not get changed outside of the function). If you wish to allow a function to modify its arguments, you must pass them by reference.

If you want an argument to a function to be passed by reference, you can prepend an ampersand (&) to the argument name in the function definition:

  void add_some_extra(real &a)  {    a=a+3;  }    b=6;  add_some_extra(b);  // b now contains 6+3=9  

In the example above the variable b has been passed to the function add_some_extra. The function argument has been passed by reference, i.e. the argument a in the function is just an alias to b. Thus any change to a inside the function will be made to b, too.

The call by reference is not a real “call by reference”. Internally it’s just a call by value with a back-assignment to the original variable:
So in the above example it’s like the following “pseudo” code:

  b=6;  Call add_some_extra, passing the value of b to that function, i.e. 6  Inside function add_some_extra:    create local variable a, set a to the value passed to the function, i.e. 6    execute a=a+3, a will contain 9.    return from function:      Assign b the value of a, i.e. b=a, i.e. b=9;  

Basically you won’t see any difference. But perhaps, if you use recursive function calls and such stuff you may see unexpected behaviour if you use call-by-reference: Keep in mind how call-by-reference has been solved!
I implemented call-by-reference in order to be able to return more than one value.

Function Arguments