25

Is there an equivalent of .net's Expression Trees that underly LINQ for the JVM? I would like to implement some LINQ like code structures in Scala and I am wondering if I have to roll my own expression tree library also.

Update: I am not interested in a linq equivalent itself. .net has a large set of expression tree tools that make it easy to dynamically compile code at runtime can have it be callable from your code. The project I want to undertake has no relation to databases. Expression tree's provide an easy way to describe code that operates on data.

If there is no library my other option I think is to create one that emits byte code.

SpringLearner
  • 13,738
  • 20
  • 78
  • 116
Steve Severance
  • 6,611
  • 1
  • 33
  • 44
  • 1
    For JAVA try Quare (codehaus). BUT, as long as JAVA doesn't support high order functions (functions as first class members) i don't believe these "libraries" will feel the real LINQ. – dz. Sep 25 '09 at 21:09
  • Steve - did you ever get anywhere with this? – MalcomTucker Jul 06 '10 at 17:18
  • 2
    No. We just went back to windows and used windows. For some stuff we used LLVM with c++ on unix. However we are isolating the java stuff and using .net for everything that requires dynamic codegen. – Steve Severance Jul 06 '10 at 17:51
  • Something in that area is Java the annotation processing tool.... But that is designed for code generation, rather than modification. http://docs.oracle.com/javase/7/docs/technotes/guides/apt/ – Aleksandr Panzin Oct 04 '13 at 17:05
  • http://stackoverflow.com/questions/25989449/parsing-and-translating-java-8-lambda-expressions – Konstantin Triger Jan 05 '15 at 23:02

2 Answers2

4

Since 2.10, Scala has macros, which give you access to abstract syntax trees of their arguments at compile-time: http://scalamacros.org/. Here are some examples of their usage including a sketch of LINQ: http://scalamacros.org/paperstalks/2013-12-02-WhatAreMacrosGoodFor.pdf.

Eugene Burmako
  • 13,028
  • 1
  • 46
  • 59
1

The closest thing I am aware of is Julian Hyde's linq4j and Optiq libraries. They have an expression tree model, support a LINQ-like model of programming (subject to Java syntax) against many types of data sources.

Ross Judson
  • 1,132
  • 5
  • 11