Previous Up Next

12.1.4  Default values of the parameters

You can give the parameters of a function default values by putting parameter=value in the parameter list of the function. For example, if you define a function:
Input:

f(x,y=5,z):= {
return x*y*z;
}

then:
Input:

f(1,2,3)

Output:

6

since the product 1*2*3=6. If you give f only two values as input:
Input:

f(3,4)

Output:

60

since the values 3 and 4 will be given to the parameters which don’t have default values; in this case, y will get its default value 5 while 3 and 4 will be assigned to x and z, respectively. The result is x*y*z=3*5*4=60.


Previous Up Next