What functional constructs to use for ShapeLogic
I have started to code the lazy streams for ShapeLogic. They are going to be key for the query interface to ShapeLogic. I need some functional constructs to work with these. The top sources candidates are:- Apache Commons
- Groovy
- Java 7
- Hand coding
Apache Commons functional constructs
I am currently using Apache Commons JEXL for user expressions.- Apache Commons do not use templates
- Apache Commons Functor are still in the sandbox and not actively developed
- The code is not uniform
- You cannot make user define functions in Apache Commons JEXL
Groovy functional constructs
I need to use a scripting language, to define user functions.- Groovy contains all of Java's constructs
- Groovy comes with good functional constructs
- I like the Groovy syntax for using these
- I cannot use these expressions directly since Groovy is not a lazy language
Java 7 functional constructs
Java 7 comes with good functional constructs.- There are a lot of interest for functional constructs in Java 7
- I would rather use Java 7 than compete with it
- Java 7 still seem to be pretty far away
- It is not sure that closures will make it into Java 7
Thoughts on immutable constructs
I will probably make the convention that a lazy stream like the Fibonacci numbers are immutable, but not enforce this by making a LISP list.Scala envy
Now I suffer from Scala language envy. These Scala language features would come in handy now:- Lazy streams
- List comprehension, with same syntax for lists, iterators and streams
- First class function
- Closures
- Lazy calculation
- Uniform access to functions and lists
Hand coding functional constructs
This might not be too much work, but I would rather not create yet another implementation of functional constructs. Apache Commons Functor never took off, despite some good press. That is probably an indication that Java was not that well suited for elegant functional constructs when this library was made, and maybe still isn't.Current work plan
- I will start by implementing a lazy Fibonacci stream
- Then I will move the polygon finder to a lazy stream, before it could only find one polygon
If you know of any libraries that would fit my need and not be too heavyweight, please let me know.
Two Fibonacci implementations
The Haskell language has an incredibly elegant lazy stream implementation:fibs :: [Int]
fibs = 1 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]
Drools Fibonacci implemented. This is not a good fit for my computer vision project.
-Sami Badawi
1 comment:
Other options:
- FunctionalJava
- Clojure
It's unlikely I think that closures will be in Java 7.
Post a Comment