Last active
August 29, 2015 14:10
-
-
Save mrbrdo/5d5ee91b0969fcd487fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def x: Int = { println("x()"); 1 } | |
def a(byName1: => Int, byName2: => Int): Unit = { | |
println("a()") | |
println(byName1 + byName2) | |
} | |
a(x * 2, x * 3) | |
// output (note when x is actually called): | |
// a() | |
// x() | |
// x() | |
// 5 | |
// equivalent call in Ruby: a( proc { x * 2 }, proc { x * 3 } ) | |
// but syntax in Ruby is too verbose to actually design APIs like this | |
// hard to implement in Ruby VM but easy "cheating" could be in method naming | |
// e.g. a@(x * 2, x * 3) or some other syntax sugar | |
// it would be ok since: SyntaxError: `@(' is not allowed as an instance variable name | |
// it might actually be even better because you know what will happen with your parameters | |
// when you call the method (because of different syntax in method call) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This reminds me of C++ reference type, which I don't like at all.
The semantics of expression should be recognized at a glance.
In that sense, I don't like macros neither.
What do you use name parameter for?