« Return to Thread: getter / setter questions

Re: getter / setter questions

by Daniel Sobral :: Rate this Message:

Reply to Author | View in Thread

Ah, I understand now! Indeed, that is curious. The book says the following on assinments:
 

The interpretation of an assignment to a simple variable

x = e depends on the

definition of

x. If x denotes a mutable variable, then the assignment changes the

current value of

x to be the result of evaluating the expression e. The type of e is

expected to conform to the type of

x. If x is a parameterless function defined in

some template, and the same template contains a setter function

x_= as member,

then the assignment

x = e is interpreted as the invocation x_=(e ) of that setter

function. Analogously, an assignment

f .x = e to a parameterless function x is

interpreted as the invocation

f .x_=(e ).

 
So, here it is: "If x is a parameterless function defined in some template, and the same template contains a setter function x_= as member". The same-name getter is a requirement. It's probably a matter of consistency: getters and setters are a way to make something look like a var, while hiding the actual implementation.


On Wed, Jul 8, 2009 at 6:37 AM, Michael <micha-1@...> wrote:
Am Wednesday 08 July 2009 11:16:41 schrieb Ricky Clarkson:
> I think it's reasonably obvious that bar isn't the name of a setter for
> foo.

a setter can be just some function, like written here:
on page 392 and 393 of the "Programming in Scala" book there is an example
where they define conversion functions to and from fahrenheit to and from
celsius with a getter and a setter function. This looked to me like I can
choose the names for getters and setters arbitray. But maybe just my english
sucks and I understood something which isn't there :-)

cheers
 Michael



--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.

 « Return to Thread: getter / setter questions