This page is no longer maintained — Please continue to the home page at www.scala-lang.org

(puzzly,puzzle)

9 replies
Razvan Cojocaru
Joined: 2009-10-21,
User offline. Last seen 42 years 45 weeks ago.

Sorry - at the end of a really long day here and I can't think any
more...What exactly happens here?

println "puzzly"
// doesn't compile
println ("puzzly")
// prints: puzzly
println ("puzzly", "puzzle")
// prints: (puzzly,puzzle)

Did the pair turn into a tuple which passed itself as a single argument
without () ?

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech

Roland Kuhn
Joined: 2008-12-26,
User offline. Last seen 3 years 14 weeks ago.
Re: (puzzly,puzzle)

Welcome to Scala version 2.7.1.final (Java HotSpot(TM) 64-Bit Server
VM, Java 1.6.0_15).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def f(x:AnyRef){println(x.getClass.getName)}
f: (AnyRef)Unit

scala> f(2,3)
scala.Tuple2

So, this has been around for quite a while. But it was also unexpected
for me… So, one must be aware that a method which accepts one AnyRef
is not as arity-checked as one might expect.

Regards,

Roland

On Nov 19, 2009, at 22:17 , Razvan Cojocaru wrote:

>
> Sorry - at the end of a really long day here and I can't think any
> more...What exactly happens here?
>
> println "puzzly"
> // doesn't compile
> println ("puzzly")
> // prints: puzzly
> println ("puzzly", "puzzle")
> // prints: (puzzly,puzzle)
>
> Did the pair turn into a tuple which passed itself as a single
> argument
> without () ?
>
> -----
> Razvan Cojocaru,
> Work: http://www.sigma-systems.com
> Me: http://feeds.razie.com/RazvanTech

Ishaaq Chandy
Joined: 2009-02-16,
User offline. Last seen 42 years 45 weeks ago.
Re: (puzzly,puzzle)
Actually, now that I look at it - it is a bit more puzzling than that. It is obvious to me that ("puzzly", "puzzle") is being converted into a single Tuple argument and passed to println because println takes an AnyRef. Simple enough. However, what is not so obvious, is that, given:
println "puzzly" // does not compile
println("puzzly") //compiles

shouldn't it be that:
println ("puzzly", "puzzle") // compiles, but should not, instead you should have to use the following form:
println(("puzzly", "puzzle"))

???

2009/11/20 Roland Kuhn <rk [at] rkuhn [dot] info>
Welcome to Scala version 2.7.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_15).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def f(x:AnyRef){println(x.getClass.getName)}
f: (AnyRef)Unit

scala> f(2,3)
scala.Tuple2

So, this has been around for quite a while. But it was also unexpected for me… So, one must be aware that a method which accepts one AnyRef is not as arity-checked as one might expect.

Regards,

Roland

On Nov 19, 2009, at 22:17 , Razvan Cojocaru wrote:


Sorry - at the end of a really long day here and I can't think any
more...What exactly happens here?

    println "puzzly"
// doesn't compile
    println ("puzzly")
// prints: puzzly
    println ("puzzly", "puzzle")
// prints:  (puzzly,puzzle)

Did the pair turn into a tuple which passed itself as a single argument
without () ?

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech
nilskp
Joined: 2009-01-30,
User offline. Last seen 1 year 27 weeks ago.
Re: (puzzly,puzzle)
I think overloading is at play here.

println // No-args

is a valid method.

On Thu, Nov 19, 2009 at 5:06 PM, Ishaaq Chandy <ishaaq [at] gmail [dot] com> wrote:
Actually, now that I look at it - it is a bit more puzzling than that. It is obvious to me that ("puzzly", "puzzle") is being converted into a single Tuple argument and passed to println because println takes an AnyRef. Simple enough. However, what is not so obvious, is that, given:
println "puzzly" // does not compile
println("puzzly") //compiles

shouldn't it be that:
println ("puzzly", "puzzle") // compiles, but should not, instead you should have to use the following form:
println(("puzzly", "puzzle"))

???

2009/11/20 Roland Kuhn <rk [at] rkuhn [dot] info>
Welcome to Scala version 2.7.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_15).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def f(x:AnyRef){println(x.getClass.getName)}
f: (AnyRef)Unit

scala> f(2,3)
scala.Tuple2

So, this has been around for quite a while. But it was also unexpected for me… So, one must be aware that a method which accepts one AnyRef is not as arity-checked as one might expect.

Regards,

Roland

On Nov 19, 2009, at 22:17 , Razvan Cojocaru wrote:


Sorry - at the end of a really long day here and I can't think any
more...What exactly happens here?

    println "puzzly"
// doesn't compile
    println ("puzzly")
// prints: puzzly
    println ("puzzly", "puzzle")
// prints:  (puzzly,puzzle)

Did the pair turn into a tuple which passed itself as a single argument
without () ?

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech
ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: (puzzly,puzzle)
Scala is generally rather flexible about use of parentheses.  In particular, it's okay (as Roland demonstrated) to omit the extra set of parentheses when passing a tuple to a function (though it will look for a function with a parameter list of the right length first).  So, for example:

object O {
  def f[A](a:(A,A))=a._1
  def g[A](a:(A,A))=a._1
  def g[A](a1:A,a2:A)=a2
  def h(a:AnyRef)=a.toString
}

scala> O.f(7,5)
res0: Int = 7

scala> O.f((7,5))
res1: Int = 7

scala> O.g(7,5)  // This calls the version with a1, a2 parameters
res2: Int = 5

scala> O.g((7,5))   // Now we're explicitly specifying the tuple
res3: Int = 7

scala> O.h(7,5)  // Tuple2[Int,Int] fits into AnyRef, so this works
res4: java.lang.String = (7,5)

scala> O.h((7,5))  // Explicitly passing the tuple works too
res5: java.lang.String = (7,5)

So, since println takes an AnyRef, if you call it with a list of parameters:
  println("My","dog","has","fleas")
it will first look for println(String,String,String,String) and similar generic versions thereof (which do not exist), and then will realize that the tuple
  ("My","dog","has","fleas")
is a Tuple4 which is a Product4 which is a Product which is an AnyRef, at which point it will find
  println(AnyRef)
and happily pass the tuple in.

  --Rex

P.S. Exercise: if you add
  def h(p:Product)=p.productArity
to object O above, what will O.h(7,5) return then?


On Thu, Nov 19, 2009 at 4:17 PM, Razvan Cojocaru <razvanc99 [at] gmail [dot] com> wrote:

Sorry - at the end of a really long day here and I can't think any
more...What exactly happens here?

     println "puzzly"
// doesn't compile
     println ("puzzly")
// prints: puzzly
     println ("puzzly", "puzzle")
// prints:  (puzzly,puzzle)

Did the pair turn into a tuple which passed itself as a single argument
without () ?

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech
--
View this message in context: http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26421485.html
Sent from the Scala - User mailing list archive at Nabble.com.


Razvan Cojocaru 2
Joined: 2009-11-20,
User offline. Last seen 42 years 45 weeks ago.
Re: (puzzly,puzzle)

it's getting annoying - is this a bug?

in Predef.scala:
def println(x: Any) = Console.println(x)

// this doesn't comiple
// println "puzzly"

// this works fine:
Console println "puzzly"

For some reason, I can't see the source code for Console...

Rex Kerr-2 wrote:
>
> Scala is generally rather flexible about use of parentheses. In
> particular,
> it's okay (as Roland demonstrated) to omit the extra set of parentheses
> when
> passing a tuple to a function (though it will look for a function with a
> parameter list of the right length first). So, for example:
>
> object O {
> def f[A](a:(A,A))=a._1
> def g[A](a:(A,A))=a._1
> def g[A](a1:A,a2:A)=a2
> def h(a:AnyRef)=a.toString
> }
>
> scala> O.f(7,5)
> res0: Int = 7
>
> scala> O.f((7,5))
> res1: Int = 7
>
> scala> O.g(7,5) // This calls the version with a1, a2 parameters
> res2: Int = 5
>
> scala> O.g((7,5)) // Now we're explicitly specifying the tuple
> res3: Int = 7
>
> scala> O.h(7,5) // Tuple2[Int,Int] fits into AnyRef, so this works
> res4: java.lang.String = (7,5)
>
> scala> O.h((7,5)) // Explicitly passing the tuple works too
> res5: java.lang.String = (7,5)
>
> So, since println takes an AnyRef, if you call it with a list of
> parameters:
> println("My","dog","has","fleas")
> it will first look for println(String,String,String,String) and similar
> generic versions thereof (which do not exist), and then will realize that
> the tuple
> ("My","dog","has","fleas")
> is a Tuple4 which is a Product4 which is a Product which is an AnyRef, at
> which point it will find
> println(AnyRef)
> and happily pass the tuple in.
>
> --Rex
>
> P.S. Exercise: if you add
> def h(p:Product)=p.productArity
> to object O above, what will O.h(7,5) return then?
>
>
> On Thu, Nov 19, 2009 at 4:17 PM, Razvan Cojocaru
> wrote:
>
>>
>> Sorry - at the end of a really long day here and I can't think any
>> more...What exactly happens here?
>>
>> println "puzzly"
>> // doesn't compile
>> println ("puzzly")
>> // prints: puzzly
>> println ("puzzly", "puzzle")
>> // prints: (puzzly,puzzle)
>>
>> Did the pair turn into a tuple which passed itself as a single argument
>> without () ?
>>
>> -----
>> Razvan Cojocaru,
>> Work: http://www.sigma-systems.com
>> Me: http://feeds.razie.com/RazvanTech
>> --
>> View this message in context:
>> http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26421485.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>

-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: (puzzly,puzzle)
No, it is not a bug. The thing that compiles is in operator style. Operator syle requires one of the three conditions:   1) method preceeding object, with method called !, ~, + or -, and the object having an equivalent unary_X method defined for the operator X in question.   2) object method parameters. If a single parameter is being passed, parenthesis are not required.   3) object method, for parameter-less methods, as long as it can't be read as (2) above.
In the example you gave that does not compile, you have "method parameter". That is not a valid syntax.
On Fri, Nov 20, 2009 at 7:17 PM, Razvan Cojocaru <razie [at] razie [dot] com> wrote:

it's getting annoying - is this a bug?

in Predef.scala:
 def println(x: Any) = Console.println(x)

// this doesn't comiple
//      println "puzzly"

// this works fine:
     Console println "puzzly"

For some reason, I can't see the source code for Console...


Rex Kerr-2 wrote:
>
> Scala is generally rather flexible about use of parentheses.  In
> particular,
> it's okay (as Roland demonstrated) to omit the extra set of parentheses
> when
> passing a tuple to a function (though it will look for a function with a
> parameter list of the right length first).  So, for example:
>
> object O {
>   def f[A](a:(A,A))=a._1
>   def g[A](a:(A,A))=a._1
>   def g[A](a1:A,a2:A)=a2
>   def h(a:AnyRef)=a.toString
> }
>
> scala> O.f(7,5)
> res0: Int = 7
>
> scala> O.f((7,5))
> res1: Int = 7
>
> scala> O.g(7,5)  // This calls the version with a1, a2 parameters
> res2: Int = 5
>
> scala> O.g((7,5))   // Now we're explicitly specifying the tuple
> res3: Int = 7
>
> scala> O.h(7,5)  // Tuple2[Int,Int] fits into AnyRef, so this works
> res4: java.lang.String = (7,5)
>
> scala> O.h((7,5))  // Explicitly passing the tuple works too
> res5: java.lang.String = (7,5)
>
> So, since println takes an AnyRef, if you call it with a list of
> parameters:
>   println("My","dog","has","fleas")
> it will first look for println(String,String,String,String) and similar
> generic versions thereof (which do not exist), and then will realize that
> the tuple
>   ("My","dog","has","fleas")
> is a Tuple4 which is a Product4 which is a Product which is an AnyRef, at
> which point it will find
>   println(AnyRef)
> and happily pass the tuple in.
>
>   --Rex
>
> P.S. Exercise: if you add
>   def h(p:Product)=p.productArity
> to object O above, what will O.h(7,5) return then?
>
>
> On Thu, Nov 19, 2009 at 4:17 PM, Razvan Cojocaru
> <razvanc99 [at] gmail [dot] com>wrote:
>
>>
>> Sorry - at the end of a really long day here and I can't think any
>> more...What exactly happens here?
>>
>>      println "puzzly"
>> // doesn't compile
>>      println ("puzzly")
>> // prints: puzzly
>>      println ("puzzly", "puzzle")
>> // prints:  (puzzly,puzzle)
>>
>> Did the pair turn into a tuple which passed itself as a single argument
>> without () ?
>>
>> -----
>> Razvan Cojocaru,
>> Work: http://www.sigma-systems.com
>> Me: http://feeds.razie.com/RazvanTech
>> --
>> View this message in context:
>> http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26421485.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>


-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech
--
View this message in context: http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26449902.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Veni, vidi, veterni.
Ishaaq Chandy
Joined: 2009-02-16,
User offline. Last seen 42 years 45 weeks ago.
Re: (puzzly,puzzle)
Yes, that is what I understood too, however it still does not explain why:

println "puzzly"

does not work (which I knew and expected anyway), but:

println ("puzzly", "puzzle")

does work - which was a surprise, because, to me, it is exactly the same syntax as the first - the only difference being that the argument is a tuple instead of a String.

So, the only reason it would work is if the compiler makes a special case for tuples - whereas, all through the staircase book we're given the impression that Scala, in fact, strives to not make special case rules (unlike Java).

Not really complaining - just saying that it is a surprising to me.

Ishaaq

2009/11/21 Daniel Sobral <dcsobral [at] gmail [dot] com>
No, it is not a bug. The thing that compiles is in operator style. Operator syle requires one of the three conditions:   1) method preceeding object, with method called !, ~, + or -, and the object having an equivalent unary_X method defined for the operator X in question.   2) object method parameters. If a single parameter is being passed, parenthesis are not required.   3) object method, for parameter-less methods, as long as it can't be read as (2) above.
In the example you gave that does not compile, you have "method parameter". That is not a valid syntax.
On Fri, Nov 20, 2009 at 7:17 PM, Razvan Cojocaru <razie [at] razie [dot] com> wrote:

it's getting annoying - is this a bug?

in Predef.scala:
 def println(x: Any) = Console.println(x)

// this doesn't comiple
//      println "puzzly"

// this works fine:
     Console println "puzzly"

For some reason, I can't see the source code for Console...


Rex Kerr-2 wrote:
>
> Scala is generally rather flexible about use of parentheses.  In
> particular,
> it's okay (as Roland demonstrated) to omit the extra set of parentheses
> when
> passing a tuple to a function (though it will look for a function with a
> parameter list of the right length first).  So, for example:
>
> object O {
>   def f[A](a:(A,A))=a._1
>   def g[A](a:(A,A))=a._1
>   def g[A](a1:A,a2:A)=a2
>   def h(a:AnyRef)=a.toString
> }
>
> scala> O.f(7,5)
> res0: Int = 7
>
> scala> O.f((7,5))
> res1: Int = 7
>
> scala> O.g(7,5)  // This calls the version with a1, a2 parameters
> res2: Int = 5
>
> scala> O.g((7,5))   // Now we're explicitly specifying the tuple
> res3: Int = 7
>
> scala> O.h(7,5)  // Tuple2[Int,Int] fits into AnyRef, so this works
> res4: java.lang.String = (7,5)
>
> scala> O.h((7,5))  // Explicitly passing the tuple works too
> res5: java.lang.String = (7,5)
>
> So, since println takes an AnyRef, if you call it with a list of
> parameters:
>   println("My","dog","has","fleas")
> it will first look for println(String,String,String,String) and similar
> generic versions thereof (which do not exist), and then will realize that
> the tuple
>   ("My","dog","has","fleas")
> is a Tuple4 which is a Product4 which is a Product which is an AnyRef, at
> which point it will find
>   println(AnyRef)
> and happily pass the tuple in.
>
>   --Rex
>
> P.S. Exercise: if you add
>   def h(p:Product)=p.productArity
> to object O above, what will O.h(7,5) return then?
>
>
> On Thu, Nov 19, 2009 at 4:17 PM, Razvan Cojocaru
> <razvanc99 [at] gmail [dot] com>wrote:
>
>>
>> Sorry - at the end of a really long day here and I can't think any
>> more...What exactly happens here?
>>
>>      println "puzzly"
>> // doesn't compile
>>      println ("puzzly")
>> // prints: puzzly
>>      println ("puzzly", "puzzle")
>> // prints:  (puzzly,puzzle)
>>
>> Did the pair turn into a tuple which passed itself as a single argument
>> without () ?
>>
>> -----
>> Razvan Cojocaru,
>> Work: http://www.sigma-systems.com
>> Me: http://feeds.razie.com/RazvanTech
>> --
>> View this message in context:
>> http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26421485.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>


-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech
--
View this message in context: http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26449902.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Veni, vidi, veterni.

bmaso
Joined: 2009-10-04,
User offline. Last seen 2 years 40 weeks ago.
Re: (puzzly,puzzle)
Looks like an accidental corner-case to me. I'm going to treat it that way.

Best regards,
Brian Maso
(949) 395-8551
brian [at] blumenfeld-maso [dot] com
twitter: @bmaso
skype: brian.maso
LinkedIn: http://www.linkedin.com/in/brianmaso

On Sat, Nov 21, 2009 at 1:31 AM, Ishaaq Chandy <ishaaq [at] gmail [dot] com> wrote:
Yes, that is what I understood too, however it still does not explain why:

println "puzzly"

does not work (which I knew and expected anyway), but:

println ("puzzly", "puzzle")

does work - which was a surprise, because, to me, it is exactly the same syntax as the first - the only difference being that the argument is a tuple instead of a String.

So, the only reason it would work is if the compiler makes a special case for tuples - whereas, all through the staircase book we're given the impression that Scala, in fact, strives to not make special case rules (unlike Java).

Not really complaining - just saying that it is a surprising to me.

Ishaaq

2009/11/21 Daniel Sobral <dcsobral [at] gmail [dot] com>
No, it is not a bug. The thing that compiles is in operator style. Operator syle requires one of the three conditions:   1) method preceeding object, with method called !, ~, + or -, and the object having an equivalent unary_X method defined for the operator X in question.   2) object method parameters. If a single parameter is being passed, parenthesis are not required.   3) object method, for parameter-less methods, as long as it can't be read as (2) above.
In the example you gave that does not compile, you have "method parameter". That is not a valid syntax.
On Fri, Nov 20, 2009 at 7:17 PM, Razvan Cojocaru <razie [at] razie [dot] com> wrote:

it's getting annoying - is this a bug?

in Predef.scala:
 def println(x: Any) = Console.println(x)

// this doesn't comiple
//      println "puzzly"

// this works fine:
     Console println "puzzly"

For some reason, I can't see the source code for Console...


Rex Kerr-2 wrote:
>
> Scala is generally rather flexible about use of parentheses.  In
> particular,
> it's okay (as Roland demonstrated) to omit the extra set of parentheses
> when
> passing a tuple to a function (though it will look for a function with a
> parameter list of the right length first).  So, for example:
>
> object O {
>   def f[A](a:(A,A))=a._1
>   def g[A](a:(A,A))=a._1
>   def g[A](a1:A,a2:A)=a2
>   def h(a:AnyRef)=a.toString
> }
>
> scala> O.f(7,5)
> res0: Int = 7
>
> scala> O.f((7,5))
> res1: Int = 7
>
> scala> O.g(7,5)  // This calls the version with a1, a2 parameters
> res2: Int = 5
>
> scala> O.g((7,5))   // Now we're explicitly specifying the tuple
> res3: Int = 7
>
> scala> O.h(7,5)  // Tuple2[Int,Int] fits into AnyRef, so this works
> res4: java.lang.String = (7,5)
>
> scala> O.h((7,5))  // Explicitly passing the tuple works too
> res5: java.lang.String = (7,5)
>
> So, since println takes an AnyRef, if you call it with a list of
> parameters:
>   println("My","dog","has","fleas")
> it will first look for println(String,String,String,String) and similar
> generic versions thereof (which do not exist), and then will realize that
> the tuple
>   ("My","dog","has","fleas")
> is a Tuple4 which is a Product4 which is a Product which is an AnyRef, at
> which point it will find
>   println(AnyRef)
> and happily pass the tuple in.
>
>   --Rex
>
> P.S. Exercise: if you add
>   def h(p:Product)=p.productArity
> to object O above, what will O.h(7,5) return then?
>
>
> On Thu, Nov 19, 2009 at 4:17 PM, Razvan Cojocaru
> <razvanc99 [at] gmail [dot] com>wrote:
>
>>
>> Sorry - at the end of a really long day here and I can't think any
>> more...What exactly happens here?
>>
>>      println "puzzly"
>> // doesn't compile
>>      println ("puzzly")
>> // prints: puzzly
>>      println ("puzzly", "puzzle")
>> // prints:  (puzzly,puzzle)
>>
>> Did the pair turn into a tuple which passed itself as a single argument
>> without () ?
>>
>> -----
>> Razvan Cojocaru,
>> Work: http://www.sigma-systems.com
>> Me: http://feeds.razie.com/RazvanTech
>> --
>> View this message in context:
>> http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26421485.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>


-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech
--
View this message in context: http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26449902.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Veni, vidi, veterni.


dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: (puzzly,puzzle)
I think you got it the other way around. Scala is converting multiple parameters into a tuple, not a tuple into a parameter.

On Sat, Nov 21, 2009 at 7:31 AM, Ishaaq Chandy <ishaaq [at] gmail [dot] com> wrote:
Yes, that is what I understood too, however it still does not explain why:

println "puzzly"

does not work (which I knew and expected anyway), but:

println ("puzzly", "puzzle")

does work - which was a surprise, because, to me, it is exactly the same syntax as the first - the only difference being that the argument is a tuple instead of a String.

So, the only reason it would work is if the compiler makes a special case for tuples - whereas, all through the staircase book we're given the impression that Scala, in fact, strives to not make special case rules (unlike Java).

Not really complaining - just saying that it is a surprising to me.

Ishaaq

2009/11/21 Daniel Sobral <dcsobral [at] gmail [dot] com>
No, it is not a bug. The thing that compiles is in operator style. Operator syle requires one of the three conditions:   1) method preceeding object, with method called !, ~, + or -, and the object having an equivalent unary_X method defined for the operator X in question.   2) object method parameters. If a single parameter is being passed, parenthesis are not required.   3) object method, for parameter-less methods, as long as it can't be read as (2) above.
In the example you gave that does not compile, you have "method parameter". That is not a valid syntax.
On Fri, Nov 20, 2009 at 7:17 PM, Razvan Cojocaru <razie [at] razie [dot] com> wrote:

it's getting annoying - is this a bug?

in Predef.scala:
 def println(x: Any) = Console.println(x)

// this doesn't comiple
//      println "puzzly"

// this works fine:
     Console println "puzzly"

For some reason, I can't see the source code for Console...


Rex Kerr-2 wrote:
>
> Scala is generally rather flexible about use of parentheses.  In
> particular,
> it's okay (as Roland demonstrated) to omit the extra set of parentheses
> when
> passing a tuple to a function (though it will look for a function with a
> parameter list of the right length first).  So, for example:
>
> object O {
>   def f[A](a:(A,A))=a._1
>   def g[A](a:(A,A))=a._1
>   def g[A](a1:A,a2:A)=a2
>   def h(a:AnyRef)=a.toString
> }
>
> scala> O.f(7,5)
> res0: Int = 7
>
> scala> O.f((7,5))
> res1: Int = 7
>
> scala> O.g(7,5)  // This calls the version with a1, a2 parameters
> res2: Int = 5
>
> scala> O.g((7,5))   // Now we're explicitly specifying the tuple
> res3: Int = 7
>
> scala> O.h(7,5)  // Tuple2[Int,Int] fits into AnyRef, so this works
> res4: java.lang.String = (7,5)
>
> scala> O.h((7,5))  // Explicitly passing the tuple works too
> res5: java.lang.String = (7,5)
>
> So, since println takes an AnyRef, if you call it with a list of
> parameters:
>   println("My","dog","has","fleas")
> it will first look for println(String,String,String,String) and similar
> generic versions thereof (which do not exist), and then will realize that
> the tuple
>   ("My","dog","has","fleas")
> is a Tuple4 which is a Product4 which is a Product which is an AnyRef, at
> which point it will find
>   println(AnyRef)
> and happily pass the tuple in.
>
>   --Rex
>
> P.S. Exercise: if you add
>   def h(p:Product)=p.productArity
> to object O above, what will O.h(7,5) return then?
>
>
> On Thu, Nov 19, 2009 at 4:17 PM, Razvan Cojocaru
> <razvanc99 [at] gmail [dot] com>wrote:
>
>>
>> Sorry - at the end of a really long day here and I can't think any
>> more...What exactly happens here?
>>
>>      println "puzzly"
>> // doesn't compile
>>      println ("puzzly")
>> // prints: puzzly
>>      println ("puzzly", "puzzle")
>> // prints:  (puzzly,puzzle)
>>
>> Did the pair turn into a tuple which passed itself as a single argument
>> without () ?
>>
>> -----
>> Razvan Cojocaru,
>> Work: http://www.sigma-systems.com
>> Me: http://feeds.razie.com/RazvanTech
>> --
>> View this message in context:
>> http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26421485.html
>> Sent from the Scala - User mailing list archive at Nabble.com.
>>
>>
>
>


-----
Razvan Cojocaru,
Work: http://www.sigma-systems.com
Me: http://feeds.razie.com/RazvanTech
--
View this message in context: http://old.nabble.com/%28puzzly%2Cpuzzle%29-tp26421485p26449902.html
Sent from the Scala - User mailing list archive at Nabble.com.




--
Daniel C. Sobral

Veni, vidi, veterni.




--
Daniel C. Sobral

Veni, vidi, veterni.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland