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 ...
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?
...
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...
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...
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...
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...
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...
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");
...
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...
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.
...
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.
...
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 ...
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...
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...
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...
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...
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...
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...
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.
...
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...