public parameter

If the parameter is specified with no modifier, or with the keyword public, it is a public parameter. A public parameter is like a readonly local variable for the function, which can be accessed but not modified by the function itself. But its value can be extracted and reset in the scope where the function is visible. For example
>> f = function [public alpha = 3, public beta = 5] x -> y
         y = alpha * x + beta * y;
   end

>> f.alpha
   3
>> f.alpha = -5;
>> f.alpha
   -5
>> f.beta = 10;
>> f.beta
   10
It's impossible to change the value of a public parameter inside the function body. For example, if we do
>> f = function [public alpha = 3, public beta = 5] x -> y
            alpha = 10;
            ...
       end
>> f.alpha
        3
we merely creates a local variable whose name is alpha and value is 10. And
>> f = function [public alpha = 3, public beta = 5] x -> y
            this.alpha = 10;
            ...
       end
will result in a compile error. The purpose of this restriction is to reduce the implicit behavior of a function. The owner (the surrounding scope) of a function can always predict the behavior of a function as long as it only has public parameters because the function itself cannot change its public parameter values.



oz 2009-12-22