functional-programming

Are there any good Clojure benchmarks?

Edit: The Clojure benchmarks are up on the Benchmarks Game. I have made this question community wiki and invite others to keep it updated. Is anyone aware of benchmarks of Clojure's performance? I have done some of my own (although nothing too formal) and it didn't fair too well in comparison to other functional languages (tried...

Is it possible to construct a stringbuilder using a lambda function instead of foreach?

Possible Duplicate: LINQ to append to a StringBuilder from a String[] Forgive my functional programming noobiness, but is it even possible to use a lamba function to append each string in an array to a StringBuilder object? Is it possible to turn this code: // string[] errors = ... StringBuilder sb = new StringBuilder("<ul...

Do functional languages cope well with complexity?

I am curious how functional languages compare (in general) to more "traditional" languages such as C# and Java for large programs. Does program flow become difficult to follow more quickly than if a non-functional language is used? Are there other issues or things to consider when writing a large software project using a functional lan...

From the F# interactive, why would it not accept this?

I am using the F# CTP 1.9.7.8 and running the samples based on Tomas Petricek's article, on page 12 type MyCell(n:int) = let mutable data = n + 1 do printf "Creating MyCell(%d)" n member x.Data with get() = data and set(v) = data <- v member x.Print() = printf "Data %d" n override x.ToString() = ...

How can I code in a functional style in Perl?

How do you either: have a sub return a sub or execute text as code in Perl? Also, how do I have an anonymous function store state? ...

What are the advantages of built-in immutability of F# over C#?

I heard F# has native support for immutability but what about it that can not be replicated in C#? What do you get by an F# immutable data that you don't get from a C# immutable data? Also in F#, is there no way to create mutable data? Is everything immutable? If you use both C# and F# in an application, can you change the immutable F# ...

How does F# deal with the thousands of standard mutable types in the BCL?

Like Point, Size, etc value types. I also heard strings in .NET aren't truly immutable. Does F# use these or alternative immutable versions of them? If it uses the standard mutable BCL types, would this not compromise the whole immutability trust that F# gives both at compile and runtime? EDIT: What I meant to ask was, if you have alt...

Why did you decide "against" using Erlang?

Have you actually "tried" (means programmed in, not just read an article on it) Erlang and decided against it for a project? If so, why? Also, if you have opted to go back to your old language, or to use another functional language like F#, Haskell, Clojure, Scala, or something else then this counts too, and state why. ...

Using vs lambda.

Is it equivalent? public static void Using<T>(this T disposable, Action<T> action) where T:IDisposable { try { action(disposable); } finally { disposable.Dispose(); } } new SqlConnection("").Using(conn => { ...

Write an anonymous sub in Perl to a file for later use.

I have a Perl program that generates parsing rules as subs from an input file. The subs are anonymously defined an put into a hash. Now, I want to export that hash, with all the subs and then load them again later to use with a different program. How do I go about doing this? Is there some way to extract the code of each sub, or can ...

Merge list of maps and combine values to sets in Clojure

What function can I put as FOO here to yield true at the end? I played with hash-set (only correct for first 2 values), conj, and concat but I know I'm not handling the single-element vs set condition properly with just any of those. (defn mergeMatches [propertyMapList] "Take a list of maps and merges them combining values into a s...

Composing functions in Java?

I'm writing demo code for an API we've created and I keep running into the same problem where I'm repeating myself, over and over ad nauseum. I am painfully aware that Java is scheduled to have closures added but I don't have access to them now. Here is what is repeated all over the place that I'd like to just box into it's own little ...

Scala programmer - "should there be one obvious way to do it" or "more than one way to do it"?

I have been doing Java for a long time and started Scala about 6 months ago. I love the language. One thing that I discovered is that there are multiple ways to do things. I don't know if it is because of the nature of the language or because it's still young and evolving and idioms and best practices haven't emerged. What surprises me ...

Advantages of compilers for functional languages over compilers for imperative languages

As a follow up to this question What are the advantages of built-in immutability of F# over C#?--am I correct in assuming that the F# compiler can make certain optimizations knowing that it's dealing with largely immutable code? I mean even if a developer writes "Functional C#" the compiler wouldn't know all of the immutability that the...

How can I use map and receive an index as well in Scala?

Is there any List/Sequence built-in that behaves like map and provides the element's index as well? ...

What are the prerequisites of reading 'The Little Schemer'?

From the reviews 'The Little Schemer' looks like the book to learn functional programming techniques and theory/reasoning. I wanted to ask if this book requires me to learn basic Scheme first? or I can get the hang of it in the middle? Some background about myself to give depth to my question: I'm planning to have a crack at this book, ...

Functional Programming better to manipulate lists of database data?

Hi, I'm watching some lecture's on Functional Programming and the main 'data structure' so to say, but there really isn't one in FP, is lists, so my question is: when one deals a lot with database's and 'lists' of data, then is Functional Programming not superior to OOP? ...

How to make Scala's immutable collections hold immutable objects.

I'm evaluating Scala and am having a problem with its immutable collections. I want to make immutable collections, which are completely immutable, right down through all the contained objects, the objects they reference, ad infinitum. Is there a simple way to do this? The code on http://www.finalcog.com/immutable-containers-scala il...

Counting elements in a tree in Haskell

Hi Basically I've made a polymorphic tree data type and I need a way of counting the number of elements in a given tree. Here's the declaration for my Tree data type: data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) deriving (Eq, Ord, Show) So I can define a tree of Ints like this: t :: Tree Int t = Node (Leaf 5) 7 (Node (Lea...

Javascript Object / Function Question

I have an instance of a logging class "logger", this class has a function "log(txt)", which works. Now I am declaring a different class "Runner" and I pass it the logger instance in the constructor. Everything works until line 5, but line 7 does not write to the log: var Runner = function (logger) { // constructor: logger.log("this...