score:3
This seems like a bug to me. I could trigger this strange behaviour in scala 2.9.1, but not in scala 2.10 RC1 so I guess this was fixed at some point.
In scala 2.9.1:
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def byName(theValue : => Any)() : Any = theValue
byName: (theValue: => Any)()Any
scala> def myValue: String = { println("Computing myValue"); "hello" }
myValue: String
scala> val myHolder = byName(myValue)_
Computing myValue
myHolder: () => Any = <function0>
scala> myHolder()
res0: Any = hello
In scala 2.10-RC1:
Welcome to Scala version 2.10.0-RC1 (Java HotSpot(TM) Client VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def byName(theValue : => Any)() : Any = theValue
byName: (theValue: => Any)()Any
scala> def myValue: String = { println("Computing myValue"); "hello" }
myValue: String
scala> val myHolder = byName(myValue)_
myHolder: () => Any = <function0>
scala> myHolder()
Computing myValue
res0: Any = hello
score:2
The issues are https://issues.scala-lang.org/browse/SI-302 and https://issues.scala-lang.org/browse/SI-5610
Personally, I find what is now the "old" behavior more intuitive: Partial application means something is applied.
Or as Odersky had it:
No, that's how eta expansion is defined. You don't just wrap a lambda around the expression, you evaluate what you can first.
But conversely, it's easier to force evaluation than to devise a syntax for suspending it.
Source: stackoverflow.com
Related Query
- Scala by name parameters with multiple argument lists and currying
- Why does Scala provide both multiple parameters lists and multiple parameters per list?
- Calling Scala constructor with multiple argument lists
- Scala currying with 'byname' parameters and non-'byname' parameters
- How to apply a customized function with multiple parameters to each group of a dataframe and union the resulting dataframes in Scala Spark?
- What's the difference between multiple parameters lists and multiple parameters per list in Scala?
- Scala class members and constructor parameters name clash
- Dynamic SQL Parameters with Anorm and Scala Play Framework
- How to create a Scala class with private field with public getter, and primary constructor taking a parameter of the same name
- Scala generics with <: and multiple traits
- Scala named and default arguments in conjunction with implicit parameters
- How do you create scala anonymous function with multiple implicit parameters
- Quasiquotes for multiple parameters and parameter lists
- Scala and SLF4J :: pass multiple parameters
- Enums in Scala with multiple constructor parameters
- Multiple constructors with the same number of parameters exception while transforming data in spark using scala
- scala currying by nested functions or by multiple parameter lists
- Modifying multiple Lists inside a function and returning it in Scala
- Is it possible to have a Map[String,Any] with the name and the values of named parameters in Scala?
- Scala multiple implicit parameters with defaults resulting in ambiguous values
- Multiple parameters lists and default arguments
- Is there a way to call a function defined using `val` in Scala with the whole curly brace block as an argument and not the final result of that block?
- Calling scala abstract classes with parameters and inner classes from Java
- Auxiliary Constructor in Scala with multiple parameters
- Select column by name with multiple aggregate columns after pivot with Spark Scala
- How to get match type with multiple type parameters to work correctly in Scala 3
- Enums with parameters and methods in scala
- F-bounded types and methods with type parameters at argument and return sites
- Tail recursiveness in Scala methods with multiple parameter lists
- What is the difference between multiple argument lists and returning a function?
More Query from same tag
- how to replace letters in a string in alphabetical order
- Scala partition a set
- Understanding scala binary compatibility on my example
- Spark-Scala Convert String of Numbers to Double
- What does this piece of code mean in scala?
- What is "at" in shapeless (scala)?
- Lazy Evaluation in a Stream?
- Datanucleus Enhancer not working with GAE + Scala + Eclipse
- How to loop through the Dataframe which is of type of Array and append the value to a final Dataframe using Scala
- should I be using slf4j isTraceEnabled or not?
- Define a `Task` setting with a `Task` in sbt 0.13.13
- Error when trying to write to hdfs: Server IPC version 9 cannot communicate with client version 4
- How to use Scala implicit class in Java
- use length function in substring in spark
- What is Scala's Comparable trait?
- Cannot resolve overloaded method 'startTimerWithFixedDelay'
- Standardize an RDD
- Run a postgresql function in Play! framework
- how to check return value type in scala
- How to combine mvn clean and mvn install into a single task?
- First-class functions with type parameter
- How to make multiple HTTP GET requests based on previous future responses in Scala?
- wildcard can’t be used in wholeTextFiles
- Parametrising Scala trait
- HBase Spark - Connectivity with Spark 2.0
- How to find average of a particular field in Scala
- linking error on parsing java.time.LocalDate in scalajs
- Scala: Problems use java interfaces
- Play Framework 2.8.2 - No Json serializer found for type (subclass)
- Speed up geomesa query