Why this fails to compile:
scala> val a? = true
<console>:1: error: illegal start of simple pattern
val a? = true
^
and this works?
scala> val a_? = true
a_?: Boolean = true
A Scala method is a part of a class which has a name, a signature, optionally some annotations, and some bytecode where as a function in Scala is a complete object which can be assigned to a variable. In other words, a function, which is defined as a member of some object, is called a method.
In Scala when arguments pass through call-by-value function it compute the passed-in expression's or arguments value once before calling the function . But a call-by-Name function in Scala calls the expression and recompute the passed-in expression's value every time it get accessed inside the function.
By-name parameters are evaluated every time they are used. They won't be evaluated at all if they are unused. This is similar to replacing the by-name parameters with the passed expressions. They are in contrast to by-value parameters. To make a parameter called by-name, simply prepend => to its type.
Java and Scala both use call by value exclusively, except that the value is either a primitive or a pointer to an object. If your object contains mutable fields, then there is very little substantive difference between this and call by reference.
According to the Scala language specification (looking at 2.8, doubt things have changed much since):
idrest ::= {letter | digit} [`_' op]
That is, an identifier can start with a letter or a digit followed by an underscore character, and further operator characters. That makes identifiers such as foo_!@!
valid identifiers. Also, note that identifiers may also contain a string of operator characters alone. Consider the following REPL session:
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_16).
scala> val +aff = true
<console>:1: error: illegal start of simple pattern
val +aff = true
^
scala> val ??? = true
???: Boolean = true
scala> val foo_!@! = true
foo_!@!: Boolean = true
scala> val %^@%@ = true
%^@%@: Boolean = true
scala> val ^&*!%@ = 42
^&*!%@: Int = 42
Hope this answers your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With