Scala Improvement Proposal: Digressions
Mar. 11th, 2012 10:55 amAs Scala macros will become a major feature in upcoming 2.10 release, we would like to introduce a minor addition improving macros usability and recovering qualified substitutionality* which is otherwise lost in presence of macros.
We propose a syntax for digressions – pieces of code marked for evaluation in the outer scope. Their main purpose is exclusion of a piece of code from macro processing, but they also appear practical in some cases unrelated to macros.
// Proposed syntax:
f {... <} expr {> ...}
// Proposed translation:
lazy val v = expr
f {... v ...}
The proposed syntax would not compromise backward compatibility since the digraphs “<}” and “{>” proposed as opening and closing digression brackets are invalid character combinations in present Scala.
_____
* Qualified substitutionality is a property of pure code that all named vals can be eliminated by substituting their occurrences by their (properly amended) definitions.
We propose a syntax for digressions – pieces of code marked for evaluation in the outer scope. Their main purpose is exclusion of a piece of code from macro processing, but they also appear practical in some cases unrelated to macros.
// Proposed syntax:
f {... <} expr {> ...}
// Proposed translation:
lazy val v = expr
f {... v ...}
The proposed syntax would not compromise backward compatibility since the digraphs “<}” and “{>” proposed as opening and closing digression brackets are invalid character combinations in present Scala.
Use cases
[Дорогие товарищи, давайте сюда напридумываем хороших примеров!]_____
* Qualified substitutionality is a property of pure code that all named vals can be eliminated by substituting their occurrences by their (properly amended) definitions.