This is the syntax change discussed in this thread: http://www.nabble.com/-scala--Syntax-proposal-for-call-by-name-parameters-td16110900.html
It's mostly a syntax change proposal, with minor side effects on the semantics (function parameters can now be made vars, call by name constructor arguments introduce a member unless marked as private[this]).
It would work as follows:
- Function arguments can be marked as any of val, var, lazy val, or def (or left as they currently are) (allowing lazy val here is dependent on SI-240 ). var and lazy val do the obvious thing. val doesn't do anything and is allowed purely for the sake of syntax uniformity.
- Constructor arguments may also be marked as def
- Marking a parameter as "def" makes it a call by name parameter. This replaces the old call by name parameter syntax. Additionally, in a constructor argument it makes it a member def (unless it is marked as private[this], in which case it's just a constructor local def as usual)
The replacement of call by name parameters with def seems to be a reversion to an older syntax, but there appeared to be a reasonable amount of general opinion in favour of this and I think it would reduce the confusion call by name parameters often cause and generally make the syntax pleasantly clearer. Call by name parameters aren't types, so putting => on the type looks wrong and doesn't convey the correct meaning. Further, the def syntax has the added benefit that it reflects the common behaviour between call by name parameters and no argument defs.
The rest of this proposal is really just in aid of the same "similar things should look similar" principle and to tidy up the corners of the rest of this syntax change. Function arguments and constructor arguments are sufficiently similar that the surrounding syntax should really reflect that.
The main objection people raised to call by name parameters was the issue of them becoming members in constructor arguments. I think this is correct behaviour, and the ability to mark them private[this] makes it not a problem as you can still make them local to the constructor.
This is the syntax change discussed in this thread: http://www.nabble.com/-scala--Syntax-proposal-for-call-by-name-parameters-td16110900.html
It's mostly a syntax change proposal, with minor side effects on the semantics (function parameters can now be made vars, call by name constructor arguments introduce a member unless marked as private[this]).
It would work as follows:
The replacement of call by name parameters with def seems to be a reversion to an older syntax, but there appeared to be a reasonable amount of general opinion in favour of this and I think it would reduce the confusion call by name parameters often cause and generally make the syntax pleasantly clearer. Call by name parameters aren't types, so putting => on the type looks wrong and doesn't convey the correct meaning. Further, the def syntax has the added benefit that it reflects the common behaviour between call by name parameters and no argument defs.
The rest of this proposal is really just in aid of the same "similar things should look similar" principle and to tidy up the corners of the rest of this syntax change. Function arguments and constructor arguments are sufficiently similar that the surrounding syntax should really reflect that.
The main objection people raised to call by name parameters was the issue of them becoming members in constructor arguments. I think this is correct behaviour, and the ability to mark them private[this] makes it not a problem as you can still make them local to the constructor.