functional-programming

Help in designing a small Unit Test Macro in Clojure

I have a small unit test macro (defmacro is [expr value] `(if (= ~expr ~value) 'yes (println "Expected " ~value "In" ~expr "But Evaluated to" ~expr))) How do I correctly write the error message? Right now it gives Clojure 1.0.0- 1:1 user=> (is (+ 2 2) 4) user/yes 1:2 user=> (is (+ 2 2) 5) Expected ...

The semantics of Mathematica's Thread function, someone needs to finally put this to rest

Wolfram Research has had the same documentation for this function for the last 8 years at least: Thread[f[args]] "threads" f over any lists that appear in args. A lovely circular definition if I've ever seen one. Does anyone know what the actual semantics are and can provide a proper explanation that is non-circular? ...

Is Haskell mature enough for web applications?

Seems that there are not much work done on Haskell for web. People uses it as a learning tool for functional programming more than business. Has anyone developed and deployed web application on Haskell, yet? Please, share the links. The next session comments might change my mind and plan something else which could b...

N-queens in Haskell without list traversal

I searched the web for different solutions to the n-queens problem in Haskell but couldn't find any that could check for unsafe positions in O(1) time, like that one that you keep an array for the / diagonals and one for the \ diagonals. Most solutions I found just checked each new queen against all the previous ones. Something like thi...

Functional jQuery: Custom Events or Functions?

Being new to functional programming, I was working on my application's javascript (using jQuery exclusively), and wondering how jQuery's event system relates to it's functional programming paradigm. I have a function setupAccountHeader that could easily be either a document-bound event like $(document).bind('setupAccountHeader', functi...

Functional programming and equation solvers

Hi all, Just as a personal experiment, in order to try to learn better about programming and formal language theory and the like, I'm trying to write a language that basically takes in a bunch of equations and solves for unknowns more or less automatically or heuristically. I'm trying to do this by writing an interpreter in C. All that...

Tricky transform of hash -> array

I have a structure like this: {:foo => ['foo1', 'foo2'], :bar => ['bar1']} Which I would like to have transformed into: [[:foo, "foo1"], [:foo, "foo2"], [:bar, "bar1"]] My current solution is imperative: result = [] h.each do |k,v| v.each do |value| result << [k, value] end end While this works, I am certain that there i...

Jquery Load function issue in IE6

i am using IE6 as a browser and when i call upon a local HTML file as an overlay by using Load function it loads the page but, following things happens 1: shows a loading status bar all the time 2: All the javascript in the called page(overlay) stopped working. this is the call code $("#mainoverlay").load("card1.html"); ...

Source code of well designed functional web apps?

What are examples of well designed functional (as opposed to object oriented) web apps that make their source code available? I am currently studying the Hacker News source but I'd like to see some other non-trivial examples, ideally in clojure. For MVC there are lots of Rails and PHP apps, frameworks, and tutorials to study - what is t...

Functional Programming in Java

Is there a good library for functional programming in Java? I'm looking for stuff like Predicate and List.Find() (as a static method). Not complicated to implement, but it would be nice to find reuse a library here. ...

producer and consumer problem in haskell?

I would like to how can we implement producer/consumer in a functional programming language like Haskell? and how it will be different from an Imperative language? My understanding of functional programming language is primitive. Any help will be appreciated. ...

Brightness/exposure function with vb .net

Hello, I'm making a simple image editor in vb .net, and one of the functions is brightness/ exposure. this is how I'm doing it: For i = 0 To img.Width - 1 For j = 0 To img.Height - 1 Dim s As Color = img.GetPixel(i, j) Dim r As Integer = s.R * 2 Dim g As Integer = s.G * 2 Dim b ...

How to write an empty list using S, K and I combinators?

I know that: (cons [p] [q]) is ((s ((s i) (k [p]))) (k [q])) (car [lst]) is ([lst] k) (cdr [lst]) is ([lst] (k i)) I want to write a list like this (cons [a] (cons [b] (cons [c] [nil]))) , which is going to be something like this: ((s ((s i) (k [a]))) (k ((s ((s i) (k [b]))) (k ((s ((s i) (k [c]))) (k [nil])))))) But I don't kno...

Recursive generation + filtering. Better non-recursive ?

I have the following need (in python): generate all possible tuples of length 12 (could be more) containing either 0, 1 or 2 (basically, a ternary number with 12 digits) filter these tuples according to specific criteria, culling those not good, and keeping the ones I need. As I had to deal with small lengths until now, the function...

What would you call a non-persistent data structure that allows persistent operations?

I've got a class that is essentially mutable, but allows for some "persistent-like" operations. For example, I can mutate the object like this (in Python): # create an object with y equal to 3 and z equal to "foobar" x = MyDataStructure(y = 3, z = "foobar") x.y = 4 However, in lieu of doing things this way, there are a couple of met...

Complex mapping of array to object in Ruby

Hi, I have an array of strings: ["username", "String", "password", "String"] And I want to convert this array to a list of Field objects: class Field attr_reader :name, :type def initialize(name, type) @name = name @type = type end end So I need to map "username", "String" => Field.new("username", "Strin...

Which ML implementation for working throughthe book " purely functional datastructures"?

Hi, I was using Moscow ML to work through the exercises in PFD till I hit chapter on Lazy Evaluation. Mosml implementation does not have any thing like $ notation described in the book. Mosml comes with suspension datatype but I cannot use pattern matching as described in the book. Which implementation of ML did you use to work though...

Are programs in functional languages more likely to have stack overflows?

I am starting to learn ocaml, and am really appreciating the power of recursion in the language. However, one thing that I am worried about is stack overflows. If ocaml uses the stack for function calls, won't it eventually overflow the stack? For example, if I have the following function: let rec sum x = if x > 1 then f(x - 1) + x...

Is INRIA going to add concurrency primitives to OCaml?

By "concurrency" I mean lightweight processes like Erlang's actors and concurrent GC aimed to make such a processes work smoothly. It would be very cool if INRIA got rid of those drawbacks of the current OCaml implementation to make OCaml more prepared for the multicore future. P.S. F# isn't what I'm looking for. ...

How is debugging achieved in a lazy functional programming language?

I'd like to know how debugging is achieved in a lazy functional language. Can you use breakpoints, print statements and traditional techniques? Is this even a good idea? It is my understanding that pure functional programming does not allow side-effects, with the exception of monads. Order of execution is also not guaranteed. Would you h...