On Monday, 12 November 2012 at 23:38:43 UTC, luka8088 wrote:
What about making this a default behavior and introducing a new keyword if the function wants to modify the argument but it is not ref (pass by value) ? The reason I think that this should be a default behavior because not many functions actually modify their arguments and so it leaves a lot of space for optimization.

For example:

void f (int x, val int y, ref int z) {
  x = 1; // x is not copied
         // compiler throws an error, x is not passed by value
         // and therefor could not / should not be changed
  y = 2; // ok, y is copied
  z = 3; // ok, z is a reference
}

Your proposal isn't really related to this thread's topic, but I understand what you mean (although your code comments distract me a bit):

void f(const int x, int y, ref int z); =>
void f(int x, val/mutable int y, ref int z);

I use const/in ;) parameters a lot in my code too to prevent accidental modifications, so my function signatures may be more compact by treating normal pass-by-value parameters as const if not denoted with a special keyword. I guess it wouldn't be very important for optimization though because I'd expect the optimizer to detect unchanged parameters. Anyway, your proposal would completely break existing code.

Reply via email to