Are there problems that cannot be written using tail recursion?

Yes, actually you can take some code and convert every function call—and every return—into a tail call. What you end up with is called continuation-passing style, or CPS. For example, here’s a function containing two recursive calls: (define (count-tree t) (if (pair? t) (+ (count-tree (car t)) (count-tree (cdr t))) 1)) And here’s how it … Read more

Convert String array to Map using Java 8 Lambda expressions

You can modify your solution to collect the Stream of String arrays into a Map (instead of using forEach) : Map<String, Double> kvs = Arrays.asList(“a:1.0”, “b:2.0”, “c:3.0”) .stream() .map(elem -> elem.split(“:”)) .collect(Collectors.toMap(e -> e[0], e -> Double.parseDouble(e[1]))); Of course this solution has no protection against invalid input. Perhaps you should add a filter just in … Read more

Functional Programming in Java [closed]

FunctionalJava is the best known library; it makes use of Java closures (BGGA) for examples: final Array<Integer> a = array(1, 2, 3); final Array<Integer> b = a.map({int i => i + 42}); arrayShow(intShow).println(b); // {43,44,45} EDIT Check also lambdaj. Further EDIT BGGA is entirely optional. It just makes for nicer syntax.

Specification for a Functional Reactive Programming language

I’m glad you’re starting by asking about a specification rather than implementation first. There are a lot of ideas floating around about what FRP is. From the very start in the early 90’s (when I was working in interactive graphics at Sun Microsystems and then Microsoft Research), it has been about two properties (a) denotative … Read more

F# development and unit testing? [closed]

Test-driven developers should feel right at home in functional languages like F#: small functions that give deterministically repeatable results lend themselves perfectly to unit tests. There are also capabilities in the F# language that facilitate writing tests. Take, for example, Object Expressions. You can very easily write fakes for functions that take as their input … Read more