Make by-name parameters just sugar syntax rather than actual types

It would be nice if the syntax was changed and generalized as follows:

def foo0(def x: Int) = ... x ... x ...
foo0: (=> Int) => R


def foo1(lazy x: Int) = ... x ... x ...
foo1: (=> Int) => R

// ^ semantically equivalent to:

def foo1(def x: Int) = { lazy val tmp = x; ... tmp ... tmp ... }


def foo2(var x: Int) = ... x ... x ...
foo2: (Int) => R

// ^ semantically equivalent to:

def foo2(x: Int) = { var tmp = x; ... tmp ... tmp ... }

I reckon the lazy x: T variant is actually the one that would be most often used, rather than def x: T, which is the only thing we have today (through the weird x: => T syntax).

I recall reading that a long, long, time ago, there were discussions about allowing syntaxes around these lines in Scala.

10 Likes