scala - Combine call-by-name colon operator and space incoherency -


here following problem. when run following:

object  test {   def /:(s: => unit) = {     println("/:")     s   } }  println("a") /: test 

it prints:

a /: 

however, expecting print:

/: 

since last expression supposedly rewritten test./:(println("a")) - way, gives second value.

does know way make first syntax work, e.g. println("a") /: test call-by-name ?

edit

using desugar method, found out calls desugared differently.

> desugar { println("a") /: test}  val x$1: unit = println("a");  test./:(x$1) 

hence still wondering why choice.

it known issue. if compile -xlint option should see warning.

$ scalac -xlint temp.scala temp.scala:2: warning: by-name parameters evaluated eagerly when called                right-associative infix operator. more details, see si-1980.     def /:(s: => unit) = {         ^ 1 warning found 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -