|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
anything like LINQ?
by Raoul Duke
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message (i'm searching but haven't found a concise answer of yes yet :-)
Quaere comes close http://www.theserverside.com/news/thread.tss?thread_id=46887 but doesn't have closures etc? would this can this should this work better in with Scala? or is there another similar alternative? thanks. |
|
|
Re: anything like LINQ?
by Arrgh
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message For projection at least Scala is in reasonable shape already;
declarative insertion, deletion and updates are a different matter that might want some thought. LINQ: string [] cities = { ?Auckland?, ?Oslo?, ?Sydney?, ?Seattle?, ?Paris?, ?Los Angeles? }; IEnumerable places = from city in cities where city.Length > 5 orderby city descending select city; scala> val cities = List("Auckland", "Oslo", "Sydney", "Seattle", "Paris", "Los Angeles") scala> val places = scala.util.Sorting.stableSort(for (c <- cities if c.length > 5) yield c) places: List[java.lang.String] = List(Auckland, Los Angeles, Seattle, Sydney) It would be... interesting... to think about adding sorting to for comprehensions. :) |
|
|
Re: anything like LINQ?
by Henry Ware-2
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Hi Raoul,
The things on the Quaere page are easy in Scala with sequence comprehensions: val num= List(5, 4, 1, 3, 9, 8, 6, 7, 2, 0); val low=for (i <- num if i < 5 ) yield i; //or val low2= num.filter(_ < 5); def productNames(products: Seq[{def getProductName:String}])=for (p <- products ) yield p.getProductName; val words=List("aPPLE", "BlUeBeRrY", "cHeRry"); val upDown=for (w <- words) yield new { val lower=w.toLowerCase ; val upper=w.toUpperCase }; println(upDown.head.lower); //Seq doesn't have as sort because Seq's might be infinite. upDown.toList.sort (_.upper.length<_.lower.length).map(_.lower) // joins are easy too: val uppersWithLength= for (w<-upDown; i<- num if w.lower.length>i) yield (i,w.upper); SFAIK, there is no automatic translations of sequence comprehensions to jdbc/sql calls. -Henry On Jan 4, 2008 9:01 PM, Raoul Duke <raould@...> wrote: (i'm searching but haven't found a concise answer of yes yet :-) |
|
|
Re: anything like LINQ?
by Jorge Ortiz-3
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message SFAIK, there is no automatic translations of sequence comprehensions to jdbc/sql calls. My understanding is that this would require support for expression trees, which C# 3.0 has and Scala does not. --j |
|
|
Re: anything like LINQ?
by David MacIver
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message On Jan 5, 2008 11:31 PM, Jorge Eugenio Ortiz Hinojosa
<jorge.ortiz@...> wrote: > > > > SFAIK, there is no automatic translations of sequence comprehensions to > jdbc/sql calls. > > My understanding is that this would require support for expression trees, > which C# 3.0 has and Scala does not. Actually, it does. It's just utterly undocumented and kinda clunky. I think it's something which got half finished and then sidelined until decisions about reflection, metaprogramming, etc. were finalised. scala> import scala.reflect._; import scala.reflect._ scala> val addition : Code[(Int, Int) => Int] = _+_ addition: scala.reflect.Code[(Int, Int) => Int] = scala.reflect.Code@1a15597 scala> Print(addition); res0: String = (x$1, x$2) => x$1.$plus(x$2) scala> println(addition.tree); Function(List(LocalValue(NoSymbol,x$1,PrefixedType(ThisType(Class(scala)),Class(scala.Int))), LocalValue(NoSymbol,x$2,PrefixedType(ThisType(Class(scala)),Class(scala.Int)))),Apply(Select(Ident(LocalValue(NoSymbol,x$1,PrefixedType(ThisType(Class(scala)),Class(scala.Int)))),Method(scala.Int.$plus,MethodType(List(PrefixedType(ThisType(Class(scala)),Class(scala.Int))),PrefixedType(ThisType(Class(scala)),Class(scala.Int))))),List(Ident(LocalValue(NoSymbol,x$2,PrefixedType(ThisType(Class(scala)),Class(scala.Int))))))) I don't think I'd recommend using this in its present state. :-) Anyone more knowledgeable than me want to comment on it? |
|
|
Re: anything like LINQ?
by Jorge Ortiz-3
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Hot!
I'd love to see Expression Trees officially making it into Scala. On 1/5/08, David MacIver <david.maciver@...> wrote: On Jan 5, 2008 11:31 PM, Jorge Eugenio Ortiz Hinojosa |
|
|
Re: anything like LINQ?
by Martin Odersky
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message On Jan 6, 2008 1:54 AM, Jorge Eugenio Ortiz Hinojosa
<jorge.ortiz@...> wrote: > Hot! > > I'd love to see Expression Trees officially making it into Scala. > There's actually a move to do this, but the current approach was completely experimental and turned out to be a dead end. That's why it never got documented. But the new annotations can already refer to AST's, and we plan to generalize this. Cheers -- Martin |
| Free embeddable forum powered by Nabble | Forum Help |