tag:blogger.com,1999:blog-6373963829340632529.post5095388308494787145..comments2024-01-30T05:40:30.415-03:00Comments on Algorithmically challenged: String interpolation in Scala with RegexDanielhttp://www.blogger.com/profile/07505997833685327219noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-6373963829340632529.post-18594026872880168002010-05-15T07:44:13.919-03:002010-05-15T07:44:13.919-03:00You don't have to specify the type explicitly ...You don't have to specify the type explicitly again. This is sufficient:<br /><br />def interpolate(text: String, vars: Map[String, String]) =<br /> """\$\{([^}]+)\}""".r.replaceAllIn(text, _ match {<br /> case Regex.Groups(v) => vars.getOrElse(v, "")<br /> })<br /><br />And IMHO the "_ match" makes indeed sense as opposed to the original version.Timo Nentwignoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-63762911991834809462010-04-07T17:11:06.977-03:002010-04-07T17:11:06.977-03:00Most curious. It used to work, and it _ought_ to w...Most curious. It used to work, and it _ought_ to work, but it obviously isn't. I fixed by making the match explicit.Danielhttps://www.blogger.com/profile/07505997833685327219noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-42382326917056417492010-04-07T14:46:59.009-03:002010-04-07T14:46:59.009-03:00This comment has been removed by a blog administrator.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-20080738579485920052010-04-07T14:46:05.516-03:002010-04-07T14:46:05.516-03:00$ scala-2.8.0.r21356-b20100407020120/bin/scalac Fo...$ scala-2.8.0.r21356-b20100407020120/bin/scalac Foo.scala<br />Foo.scala:20: error: missing parameter type for expanded function ((x0$1) => x0$1 match {<br /> case Regex.Groups((v @ _)) => vars.getOrElse(v, "")<br />})<br /> """\$\{([^}]+)\}""".r.replaceAllIn(text, {<br /> ^<br />one error foundAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-1053159732889718712010-03-26T18:40:24.255-03:002010-03-26T18:40:24.255-03:00Bruno, o melhor lugar para fazer tal pergunta é ht...Bruno, o melhor lugar para fazer tal pergunta é http://www.stackoverflow.com, em minha opinião.<br /><br />Em resposta à sua pergunta, "list map (e => e + 1)" retorna uma nova lista com todos os elementos incrementados em 1.Danielhttps://www.blogger.com/profile/07505997833685327219noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-9601032968568563712010-03-26T11:48:25.065-03:002010-03-26T11:48:25.065-03:00using the same thread comments (Sorry, cant find b...using the same thread comments (Sorry, cant find better place ) to another question (easy mode) . If i desires , for exemplo, increment all elements from a List, what is the best approach ?<br /> I can´t use the foreach, allright ? Cause lists are immutable, right ?<br /> list foreach ( e => e+1 ) do not increment each element by one.<br /> What should i do ?Bruno Brasilnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-88707149280425246192010-03-23T09:59:40.691-03:002010-03-23T09:59:40.691-03:00It's not as convenient, but you might use
&quo...It's not as convenient, but you might use<br />"The %s of the %s".format("X", "Y")Ralphhttps://www.blogger.com/profile/14976919127554016544noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-855099037328885292010-03-20T01:14:28.585-03:002010-03-20T01:14:28.585-03:00or use expressions in {} in xml and convert the xm...or use expressions in {} in xml and convert the xml to string with the text method of xmlUnknownhttps://www.blogger.com/profile/17664098917612990535noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-78117620491154276472010-01-27T09:05:19.607-02:002010-01-27T09:05:19.607-02:00That is a devious idea... :-)That is a devious idea... :-)Danielhttps://www.blogger.com/profile/07505997833685327219noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-4124177001055991212010-01-27T03:45:53.671-02:002010-01-27T03:45:53.671-02:00Which could, with an implicit, written as
"T...Which could, with an implicit, written as<br /><br />"The ${name} of the ${game}".fill("name" -> "X", "game" -> "Y")Stephan Schmidthttp://www.codemonkeyism.comnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-28118908150672141962010-01-26T06:31:00.946-02:002010-01-26T06:31:00.946-02:00I guess it's this commit: http://lampsvn.epfl....I guess it's this commit: http://lampsvn.epfl.ch/trac/scala/changeset/20661Mirko Stockernoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-33099202744231933412010-01-26T01:51:35.590-02:002010-01-26T01:51:35.590-02:00What has arrived that makes that possible/easier?What has arrived that makes that possible/easier?Anonymousnoreply@blogger.com