|
View:
New views
18 Messages
—
Rating Filter:
Alert me
|
|
|
Printlnobject lists{
def main(args:Array[String]){ val nums=List(1,2,3,4,5,6,7,8,9,0) val fruits=List("Apple","Banana","Cheekoo","Jack Fruit","Grapes","Mango","Orange","Papaya") println(nums) println((nums.tail).tail) println(fruits.head) println(fruits.tail) println(fruits) } } HOW TO WRITE ALL PRINTLN 'S IN ONE LINE i AM GETTING ERROR IF I WRITE "+" IN BETWEEN so how do we do that in scala Thanks, Rajkumar Goel www.twitter.com/rajkumargoel |
|
|
Re: PrintlnOn Fri, Jul 10, 2009 at 1:01 PM, rajkumargoel_786 wrote:
> object lists{ > def main(args:Array[String]){ > val nums=List(1,2,3,4,5,6,7,8,9,0) > val fruits=List("Apple","Banana","Cheekoo","Jack > Fruit","Grapes","Mango","Orange","Papaya") > println(nums) > println((nums.tail).tail) > println(fruits.head) > println(fruits.tail) > println(fruits) > } > } > > > HOW TO WRITE ALL PRINTLN 'S IN ONE LINE > > i AM GETTING ERROR IF I WRITE "+" IN BETWEEN so how do we do that in scala > Thanks, > Rajkumar Goel > www.twitter.com/rajkumargoel > > > > ------------------------------------ > > http://twincling.org/ > http://twitter.com/twincling > ---------------------------------------- > Yahoo! Groups Links > > > > hi Rajkumar, Try this code: object lists{ def main(args:Array[String]){ val nums=List(1,2,3,4,5,6,7,8,9,0); val fruits=List("Apple","Banana","Cheekoo","Jack Fruit","Grapes","Mango","Orange","Papaya"); Console.print(nums); Console.print((nums.tail).tail); Console.print(fruits.head); Console.print(fruits.tail); Console.print(fruits); } } i've used print instead of println. I used Console.print instead of print because i am using Scala ver 2.3 and not 2.5. Also, "+" worked in my case, ie the following code worked: object lists{ def main(args:Array[String]){ val nums=List(1,2,3,4,5,6,7,8,9,0); val fruits=List("Apple","Banana","Cheekoo","Jack Fruit","Grapes","Mango","Orange","Papaya"); Console.println(fruits.head+fruits.tail); } } Regards, Kartik Nayak [Non-text portions of this message have been removed] |
|
|
Re: PrintlnHi rkg,
I dont know abt an error but I do get a warning from compiler, if I use '+', as shown below, but the program still runs( with wrong o/p) "warning: there were deprecation warnings; re-run with -deprecation for details one warning found" Now, 'println' requires its args to be of type String, if not, it internally converts them into String, by using some form of toString method. This works when u provide a single arg like ex: println(nums) But when u try to print the concatenated o/p using '+' like for example ex: println( nums + nums.tail) you are actually invoking the method called '+' defined for Lists and NOT String. The '+' method(for List) adds an element to the end of the list, instead of forming a String containing the 2 lists as you intended. If you want to use '+', one possible solution is to make sure that the args are Strings themselves before they invoke the '+' method. ex: println("" + nums + nums.tail) Adding a empty String, "", at the beginning makes sure that '+' is invoked for String like "".+(nums). The resulting String later invokes '+' again on the next arg. Since this method just seems to be some kind of hack, if anyone is aware of a proper way to do it, please let me know. Regards, Nikhil ________________________________ From: rajkumargoel_786 <rajkumargoel_786@...> To: twincling@... Sent: Friday, 10 July, 2009 1:01:22 PM Subject: [twincling] Println object lists{ def main(args:Array[ String]){ val nums=List(1, 2,3,4,5,6, 7,8,9,0) val fruits=List( "Apple"," Banana"," Cheekoo", "Jack Fruit","Grapes" ,"Mango", "Orange", "Papaya") println(nums) println((nums. tail).tail) println(fruits. head) println(fruits. tail) println(fruits) } } HOW TO WRITE ALL PRINTLN 'S IN ONE LINE i AM GETTING ERROR IF I WRITE "+" IN BETWEEN so how do we do that in scala Thanks, Rajkumar Goel www.twitter. com/rajkumargoel See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz..yahoo.com/ [Non-text portions of this message have been removed] |
|
|
Re: Println--- In twincling@..., nikhil <nik_mys@...> wrote:
> > Hi rkg, > > I dont know abt an error but I do get a warning from compiler, if I use '+', as shown below, but the > program still runs( with wrong o/p) > > "warning: there were deprecation warnings; re-run with -deprecation for details > one warning found" > > Now, > 'println' requires its args to be of type String, if not, it internally converts them into String, > by using some form of toString method. > This works when u provide a single arg like ex: println(nums) > > But when u try to print the concatenated o/p using '+' like for example > ex: println( nums + nums.tail) > you are actually invoking the method called '+' defined for Lists and NOT String. > > The '+' method(for List) adds an element to the end of the list, instead of forming a String > containing the 2 lists as you intended. > > If you want to use '+', one possible solution is to make sure that the args are Strings themselves > before they invoke the '+' method. > > ex: println("" + nums + nums.tail) > > Adding a empty String, "", at the beginning makes sure that '+' is invoked for String like > "".+(nums). The resulting String later invokes '+' again on the next arg. > > Since this method just seems to be some kind of hack, if anyone is aware of a proper > way to do it, please let me know. > > > Regards, > Nikhil > > > > > ________________________________ > From: rajkumargoel_786 <rajkumargoel_786@...> > To: twincling@... > Sent: Friday, 10 July, 2009 1:01:22 PM > Subject: [twincling] Println > > > > > > object lists{ > def main(args:Array[ String]){ > val nums=List(1, 2,3,4,5,6, 7,8,9,0) > val fruits=List( "Apple"," Banana"," Cheekoo", "Jack Fruit","Grapes" ,"Mango", "Orange", "Papaya") > println(nums) > println((nums. tail).tail) > println(fruits. head) > println(fruits. tail) > println(fruits) > } > } > > HOW TO WRITE ALL PRINTLN 'S IN ONE LINE > > i AM GETTING ERROR IF I WRITE "+" IN BETWEEN so how do we do that in scala > Thanks, > Rajkumar Goel > www.twitter. com/rajkumargoel > > > > > > See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz..yahoo.com/ > > [Non-text portions of this message have been removed] > object lists{ def main(args:Array[String]){ val nums=List(1,2,3,4,5,6,7,8,9,0) val fruits=List("Apple","Banana","Cheekoo","JackFruit","Grapes","Mango","Orange","Papaya") println((nums::(nums.tail).tail::fruits.head::fruits.tail::fruits).mkString(" ")) } } ~ ~ ~ This worked without any error,moreover If I use mkString()method with each and every time and then append the result with + operator the resultant output will be completely in String. Thanks for your reply. Thanks, RajkumarGoel www.twitter.com/rajkumargoel www.latestfever.blogspot.com |
|
|
Re: Re: PrintlnHi rkg,
The mkString() way was cool. I found another easy way. I think all collections have a toString method. So instead we can just use that. ex: println( nums.toString + nums.tail.toString + nums.tail.tail.toString) The advantage of this method is that you can easily preserve the formatting of the intended console output, without performing complex operations over Lists. Like if I want to print say a custom o/p of a Int, List, String and Array. Then it will be difficult to make it work with the cons, :: , operator as it applies to only Lists ex: val x = 3 val y = Array(1,2) val nums = List(1,2,3,4,5,6,7,8,9,0) val fruits=List("Apple","Banana"," Cheekoo","JackFruit","Grapes","Mango","Orange","Papaya") println( "List1" + nums.toString + "Int" + x + "Array" + y.toString + "List2" + fruits.toString) Hope this helps. Regards, Nikhil [Non-text portions of this message have been removed] |
|
|
Re: Re: PrintlnHi nik,
In your mail you say that we actually invoke + method for List and not for String. But String in scala is java.lang.String(You won't find "String" in Scala API)... scala> val k="SMS" k: java.lang.String = SMS All dataypes like int,folat...have a class in scala but not string as it was already there in java So Int,Float etc., have + method . So there is no "+" method in String(I am not sure)...... But then this works...... scala> val s=("SMS").+("sds") s: java.lang.String = SMSsds Can i know how??? I think both the string are objects here so there is some scalaObject or some sort of class which gets invoked....I may be completely wrong..Actually confused :) thanks, SMS On Fri, Jul 10, 2009 at 5:59 PM, nikhil m <nikhil.mishrikoti@...>wrote: > > > Hi rkg, > > The mkString() way was cool. > I found another easy way. I think all collections have a toString method. > So > instead we can just use that. > > ex: println( nums.toString + nums.tail.toString + nums.tail.tail.toString) > > The advantage of this method is that you can easily preserve the formatting > of the intended console output, > without performing complex operations over Lists. > Like if I want to print say a custom o/p of a Int, List, String and Array. > Then it will be difficult to make it work with the cons, :: , operator as > it > applies to only Lists > > ex: > > val x = 3 > val y = Array(1,2) > > val nums = List(1,2,3,4,5,6,7,8,9,0) > val fruits=List("Apple","Banana"," > Cheekoo","JackFruit","Grapes","Mango","Orange","Papaya") > > println( "List1" + nums.toString + "Int" + x + "Array" + y.toString + > "List2" + fruits.toString) > > Hope this helps. > > Regards, > Nikhil > > [Non-text portions of this message have been removed] > > > [Non-text portions of this message have been removed] |
|
|
Re: PrintlnHi Nikhil,
The way you said was cool .I was playing with now and I was hit by another new observation. this is what Happened scala> List(3,3) res0: List[Int] = List(3, 3) scala> res0.toString() res1: String = List(3, 3) scala> res0 res2: List[Int] = List(3, 3) scala> res1.length res3: Int = 10 scala> res0.length res4: Int = 2 What I observed is when we invoke toString method the entire List is converted to String and List(xxx) is also part of List. I used to think that toString method will extract the data from the list and then convert it to a string but it doesn't instead mkString does that thing. scala> res0.mkString res6: String = 33 Thanks, Rajkumar Goel www.twitter.com/rajkumargoel www.latestfever.blogspot.com |
|
|
Re: PrintlnHi sms,
Actually there is one more implementation of String which scala has Rich String ,RichString class is scala's implementation of a class like a String class in Java.But it is always not used it used only when certain functionalities can't be provided by Java's String class. It is a wrapper for Java's String class. Actually for every type int, float, all primitves of java we have a this wrapper of RichInt. I'm thinking that maybe that funcnality is carried out by RichString. Because it serves a IMplicit wrapper. hope it helps. Regards, RajkumarGoel www.twitter.com/rajkumargoel www.latestfever.blogspot.com |
|
|
Re: PrintlnHi sms,
Actually there is one more implementation of String which scala has Rich String ,RichString class is scala's implementation of a class like a String class in Java.But it is always not used it used only when certain functionalities can't be provided by Java's String class. It is a wrapper for Java's String class. Actually for every type int, float, all primitves of java we have a this wrapper of RichInt. I'm thinking that maybe that funcnality is carried out by RichString. Because it serves a IMplicit wrapper. hope it helps. Regards, RajkumarGoel www.twitter.com/rajkumargoel www.latestfever.blogspot.com |
|
|
Re: Re: PrintlnHi RKG,
I have already looked into RichString ..In Scala API RichString has only *,++ methods having special characters thanks, SMS On Fri, Jul 10, 2009 at 6:44 PM, rajkumargoel_786 < rajkumargoel_786@...> wrote: > > > Hi sms, > Actually there is one more implementation of String which scala has Rich > String ,RichString class is scala's implementation of a class like a String > class in Java.But it is always not used it used only when certain > functionalities can't be provided by Java's String class. > It is a wrapper for Java's String class. > Actually > for every type > int, > float, > all primitves of java we have a this wrapper of RichInt. > I'm thinking that maybe that funcnality is carried out by RichString. > Because it serves a IMplicit wrapper. > hope it helps. > Regards, > RajkumarGoel > > www.twitter.com/rajkumargoel > www.latestfever.blogspot.com > > > [Non-text portions of this message have been removed] |
|
|
Re: Re: PrintlnHi RKG,
Yes Rich* classes provide extra functionality.If you peek into scala API you'll find "+" method is in Int class itself not RichInt ...so similarly it should have been in String class but not in RichString... And String class is not there.......... thanks, SMS On Fri, Jul 10, 2009 at 6:42 PM, rajkumargoel_786 < rajkumargoel_786@...> wrote: > > > Hi sms, > Actually there is one more implementation of String which scala has Rich > String ,RichString class is scala's implementation of a class like a String > class in Java.But it is always not used it used only when certain > functionalities can't be provided by Java's String class. > It is a wrapper for Java's String class. > Actually > for every type > int, > float, > all primitves of java we have a this wrapper of RichInt. > I'm thinking that maybe that funcnality is carried out by RichString. > Because it serves a IMplicit wrapper. > hope it helps. > Regards, > RajkumarGoel > www.twitter.com/rajkumargoel > www.latestfever.blogspot.com > > > [Non-text portions of this message have been removed] |
|
|
Re: PrintlnHI sms,
String is there in scala .Since it imports java.lang package of java it has String class of Java. the complete to path in Java.lang package is java.lang.String. As far as + operator is concerned i am peeping in to the Object class of Scala seeeing whether it has a overloaded version of + operator. Thanks, RajkumarGoel www.twitter.com/rajkumargoel www.latestfever.blogspot.com |
|
|
Re: Re: PrintlnHi Rkg,
Yes thats what i was pointed when i said "In your mail you say that we actually invoke + method for List and not for String. But String in scala is java.lang.String(You won't find "String" in Scala API)... scala> val k="SMS" k: java.lang.String = SMS" Looking forward for your reply... thanks, SMS On Fri, Jul 10, 2009 at 7:12 PM, rajkumargoel_786 < rajkumargoel_786@...> wrote: > > > HI sms, > String is there in scala .Since it imports java.lang package of java it has > String class of Java. > the complete to path in Java.lang package is java.lang.String. > As far as + operator is concerned i am peeping in to the Object class of > Scala seeeing whether it has a overloaded version of + operator. > Thanks, > > RajkumarGoel > www.twitter.com/rajkumargoel > www.latestfever.blogspot.com > > > [Non-text portions of this message have been removed] |
|
|
Re: PrintlnHi sms,
What you said I didnot understand in the previous mail but however I came to know the mystery of "+". For finding the answer I went to Scala channel of IRC.and here is the log. [19:20] <rkg> Hi [19:20] <RSchulz> Finally! I thought maybe the Earth was finally deserted. [19:21] <rkg> I've got a doubt about + operaor [19:21] <rkg> *operator [19:21] <rkg> on String [19:21] <RSchulz> You doubt it exists? [19:21] <rkg> yes [19:21] <rkg> I serched through [19:21] <RSchulz> Why? [19:21] <rkg> the API [19:21] <rkg> when I add "a"+"b" [19:21] <rkg> I get "ab" [19:22] <RSchulz> Looks pretty real to me. [19:22] <rkg> but where is the + method [19:22] <rkg> implemented [19:22] <RSchulz> Are you a Java programmer? [19:22] <-- njbartlett has left this server. [19:22] <-- hipertracker|off has left this server. [19:23] <rkg> yes [19:23] <rkg> it [19:23] <rkg> should [19:23] <rkg> be like [19:23] <rkg> ("a").+("b") [19:23] <RSchulz> Well, in Java the compiler handles that. [19:23] <rkg> does it uses the Java + overloaded method??? [19:24] <RSchulz> I'm not 100% sure, but I think in Scala it's the same with the addition of an implicit conversion of any value to a String by calling its (class's) toString. [19:25] <rkg> I saw the API for [19:25] <rkg> Rich String [19:25] <rkg> class [19:25] <rkg> It doesn't provide [19:25] <rkg> + method [19:25] <RSchulz> No. [19:25] <RSchulz> Like I said, the compiler does part of it. [19:25] --> hipertracker has joined this channel (n=hipertra@...). [19:26] <rkg> sorry [19:26] <rkg> I din't get you [19:26] <RSchulz> Is this idle curiosity, or do you have a reason to care where string addition comes from? [19:27] <rkg> its the curiosity [19:27] <rkg> ofcourse [19:27] <rkg> It may help [19:27] <rkg> someway [19:28] <paulp_> it's in predef. [19:28] <paulp_> it's called any2stringadd. [19:28] <RSchulz> For me, string concatenation is something I use only for debugging purposes, anyway. [19:28] <rkg> ok [19:28] <rkg> is it a implicit function? [19:29] <RSchulz> That's why you sometimes get odd diagnostics if there's already a + defined on the LHS value's class but it doesn't accept String as its argument. [19:29] <rkg> yeh [19:29] <RSchulz> Or the actual type of the RHS. [19:29] <rkg> one last question [19:30] <rkg> is a implicit function [19:30] <rkg> ? [19:31] <paulp_> rkg: if it weren't implicit you'd be asking us "why am I calling any2stringadd", not "how are these added" ? [19:31] <RSchulz> Yes. You can see the "implicit" keyword in the ScalaDocs. [19:31] <rkg> Thanks [19:31] <rkg> everyBody [19:32] <rkg> Have a good day! and the answere is + is an implicit operator in predef method its name is any2stringadd. But however that was a terrif question...! :-) Hope it helps. Thanks, RajkumarGoel www.twitter.com/rajkumargoel www.latestfever.blogspot.com |
|
|
Re: Re: PrintlnHi rkg,
Thanks,Actually the method you adopted to get the answer...is gr8. I'll try that from nxt time......thanks a lot!!!!! SMS On Fri, Jul 10, 2009 at 7:37 PM, rajkumargoel_786 < rajkumargoel_786@...> wrote: > > > Hi sms, > What you said I didnot understand in the previous mail but however I came > to know the mystery of "+". > > For finding the answer I went to Scala channel of IRC.and here is the log. > [19:20] <rkg> Hi > [19:20] <RSchulz> Finally! I thought maybe the Earth was finally deserted. > [19:21] <rkg> I've got a doubt about + operaor > [19:21] <rkg> *operator > [19:21] <rkg> on String > [19:21] <RSchulz> You doubt it exists? > [19:21] <rkg> yes > [19:21] <rkg> I serched through > [19:21] <RSchulz> Why? > [19:21] <rkg> the API > [19:21] <rkg> when I add "a"+"b" > [19:21] <rkg> I get "ab" > [19:22] <RSchulz> Looks pretty real to me. > [19:22] <rkg> but where is the + method > [19:22] <rkg> implemented > [19:22] <RSchulz> Are you a Java programmer? > [19:22] <-- njbartlett has left this server. > [19:22] <-- hipertracker|off has left this server. > [19:23] <rkg> yes > [19:23] <rkg> it > [19:23] <rkg> should > [19:23] <rkg> be like > [19:23] <rkg> ("a").+("b") > [19:23] <RSchulz> Well, in Java the compiler handles that. > [19:23] <rkg> does it uses the Java + overloaded method??? > [19:24] <RSchulz> I'm not 100% sure, but I think in Scala it's the same > with the addition of an implicit conversion of any value to a String by > calling its (class's) toString. > [19:25] <rkg> I saw the API for > [19:25] <rkg> Rich String > [19:25] <rkg> class > [19:25] <rkg> It doesn't provide > [19:25] <rkg> + method > [19:25] <RSchulz> No. > [19:25] <RSchulz> Like I said, the compiler does part of it. > [19:25] --> hipertracker has joined this channel ( > n=hipertra@... <n%3Dhipertra%40193.95.179.200>). > [19:26] <rkg> sorry > [19:26] <rkg> I din't get you > [19:26] <RSchulz> Is this idle curiosity, or do you have a reason to care > where string addition comes from? > [19:27] <rkg> its the curiosity > [19:27] <rkg> ofcourse > [19:27] <rkg> It may help > [19:27] <rkg> someway > [19:28] <paulp_> it's in predef. > [19:28] <paulp_> it's called any2stringadd. > [19:28] <RSchulz> For me, string concatenation is something I use only for > debugging purposes, anyway. > [19:28] <rkg> ok > [19:28] <rkg> is it a implicit function? > [19:29] <RSchulz> That's why you sometimes get odd diagnostics if there's > already a + defined on the LHS value's class but it doesn't accept String as > its argument. > [19:29] <rkg> yeh > [19:29] <RSchulz> Or the actual type of the RHS. > [19:29] <rkg> one last question > [19:30] <rkg> is a implicit function > [19:30] <rkg> ? > [19:31] <paulp_> rkg: if it weren't implicit you'd be asking us "why am I > calling any2stringadd", not "how are these added" ? > [19:31] <RSchulz> Yes. You can see the "implicit" keyword in the ScalaDocs. > [19:31] <rkg> Thanks > [19:31] <rkg> everyBody > [19:32] <rkg> Have a good day! > > and the answere is > + is an implicit operator in predef method its name is any2stringadd. > But however that was a terrif question...! :-) > Hope it helps. > > Thanks, > RajkumarGoel > www.twitter.com/rajkumargoel > www.latestfever.blogspot.com > > > [Non-text portions of this message have been removed] |
|
|
Re: Re: PrintlnHi Rkg,
I tried out the any2stringadd function in Predef. it worked but could'nt understand the relation between + and any2stringadd so went to #scala [21:07] <SMSD> yeah [21:07] <SMSD> got it [21:08] <SMSD> but how does the scala compiler [21:08] <SMSD> know [21:08] <SMSD> + is any2stringadd [21:08] <SMSD> i mean when i call [21:08] <SMSD> + [21:08] <SMSD> it calls any2stingadd you say [21:08] <-- gnuvince_ has left this server (Read error: 60 (Operation timed out)). [21:09] <SMSD> ?? [21:09] <mapreduce> The language feature called "implicit conversions" causes that. [21:09] <SMSD> ok [21:09] <mapreduce> Please try to press enter at the end of a thought. 21:10] <wooli> please collect your thoughts first [21:10] <wooli> SMSD: http://programming-scala.labs.oreilly.com/ch08.html#Implicits [21:12] <SMSD> when i saw the scala API for an2stringadd it had scala.runtime.StringAdd beside it if i am right? but i am not able to access that page..says not authorized.......Any help? [21:12] --> headius has joined this channel (n=headius@...). [21:13] <-- yacc_ has left this server (Read error: 54 (Connection reset by peer)). [21:13] <SMSD>* implicit def any2stringadd (x : Any) : scala.runtime.StringAdd* [21:13] <Stivo> StringAdd seems to be not a real class... its probably only used inside the compiler [21:14] <mapreduce> StringAdd.scala exists in my svn checkout. [21:14] <wooli> http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_7_5_final/src/library/scala/runtime/StringAdd.scala?view=markup [21:14] --> WoofWoof has joined this channel (n=Woof@...). [21:14] <mapreduce> If there's a scaladoc problem, report a bug on trac. [21:14] <SMSD> oh excellent [21:15] <SMSD> thankks a lot it has the +method also it solves the problem Cheers Now follow the link and you will see that scala.runtime.StringAdd has a + method..........So the problem is solved thanks, SMS On Fri, Jul 10, 2009 at 7:42 PM, Mukund Deshpande < mukund.twincling@...> wrote: > Hi rkg, > > Thanks,Actually the method you adopted to get the answer...is gr8. > I'll try that from nxt time......thanks a lot!!!!! > > SMS > > > On Fri, Jul 10, 2009 at 7:37 PM, rajkumargoel_786 < > rajkumargoel_786@...> wrote: > >> >> >> Hi sms, >> What you said I didnot understand in the previous mail but however I came >> to know the mystery of "+". >> >> For finding the answer I went to Scala channel of IRC.and here is the log. >> [19:20] <rkg> Hi >> [19:20] <RSchulz> Finally! I thought maybe the Earth was finally deserted. >> [19:21] <rkg> I've got a doubt about + operaor >> [19:21] <rkg> *operator >> [19:21] <rkg> on String >> [19:21] <RSchulz> You doubt it exists? >> [19:21] <rkg> yes >> [19:21] <rkg> I serched through >> [19:21] <RSchulz> Why? >> [19:21] <rkg> the API >> [19:21] <rkg> when I add "a"+"b" >> [19:21] <rkg> I get "ab" >> [19:22] <RSchulz> Looks pretty real to me. >> [19:22] <rkg> but where is the + method >> [19:22] <rkg> implemented >> [19:22] <RSchulz> Are you a Java programmer? >> [19:22] <-- njbartlett has left this server. >> [19:22] <-- hipertracker|off has left this server. >> [19:23] <rkg> yes >> [19:23] <rkg> it >> [19:23] <rkg> should >> [19:23] <rkg> be like >> [19:23] <rkg> ("a").+("b") >> [19:23] <RSchulz> Well, in Java the compiler handles that. >> [19:23] <rkg> does it uses the Java + overloaded method??? >> [19:24] <RSchulz> I'm not 100% sure, but I think in Scala it's the same >> with the addition of an implicit conversion of any value to a String by >> calling its (class's) toString. >> [19:25] <rkg> I saw the API for >> [19:25] <rkg> Rich String >> [19:25] <rkg> class >> [19:25] <rkg> It doesn't provide >> [19:25] <rkg> + method >> [19:25] <RSchulz> No. >> [19:25] <RSchulz> Like I said, the compiler does part of it. >> [19:25] --> hipertracker has joined this channel ( >> n=hipertra@... <n%3Dhipertra%40193.95.179.200>). >> [19:26] <rkg> sorry >> [19:26] <rkg> I din't get you >> [19:26] <RSchulz> Is this idle curiosity, or do you have a reason to care >> where string addition comes from? >> [19:27] <rkg> its the curiosity >> [19:27] <rkg> ofcourse >> [19:27] <rkg> It may help >> [19:27] <rkg> someway >> [19:28] <paulp_> it's in predef. >> [19:28] <paulp_> it's called any2stringadd. >> [19:28] <RSchulz> For me, string concatenation is something I use only for >> debugging purposes, anyway. >> [19:28] <rkg> ok >> [19:28] <rkg> is it a implicit function? >> [19:29] <RSchulz> That's why you sometimes get odd diagnostics if there's >> already a + defined on the LHS value's class but it doesn't accept String as >> its argument. >> [19:29] <rkg> yeh >> [19:29] <RSchulz> Or the actual type of the RHS. >> [19:29] <rkg> one last question >> [19:30] <rkg> is a implicit function >> [19:30] <rkg> ? >> [19:31] <paulp_> rkg: if it weren't implicit you'd be asking us "why am I >> calling any2stringadd", not "how are these added" ? >> [19:31] <RSchulz> Yes. You can see the "implicit" keyword in the >> ScalaDocs. >> [19:31] <rkg> Thanks >> [19:31] <rkg> everyBody >> [19:32] <rkg> Have a good day! >> >> and the answere is >> + is an implicit operator in predef method its name is any2stringadd. >> But however that was a terrif question...! :-) >> Hope it helps. >> >> Thanks, >> RajkumarGoel >> www.twitter.com/rajkumargoel >> www.latestfever.blogspot.com >> >> >> > > [Non-text portions of this message have been removed] |
|
|
Re: Re: PrintlnHi Guys,
Sorry I couldnt reply sooner. Was travelling. Looks like you guys had a lot of fun :) Regards, Nikhil [Non-text portions of this message have been removed] |
|
|
Re: Re: PrintlnYeh learnt good
On Sun, Jul 12, 2009 at 4:31 PM, nikhil m <nikhil.mishrikoti@...>wrote: > > > Hi Guys, > > Sorry I couldnt reply sooner. Was travelling. Looks like you guys had a lot > of fun :) > > Regards, > Nikhil > > > [Non-text portions of this message have been removed] > > > -- Regards, Rajkumar Goel www.twitter.com/rajkumargoel www.latestfever.blogspot.com [Non-text portions of this message have been removed] |
| Free embeddable forum powered by Nabble | Forum Help |