I have this code:
#include <iostream>
#include <functional>
struct A
{
int operator()(int i) const {
std::cout << "F: " << i << std::endl;
return i + 1;
}
};
int main()
{
A a;
std::tr1::function<int(int)> f = std::tr1::ref(a);
std::cout << f(6) << std::endl;
}
The aim is to pass the functor object...
This is a problem that I can easily enough solve in a non-functional manner.
But solving it in Haskell is giving me big problems. Me being inexperienced when it comes to functional programming is surely a reason.
The problem:
I have a 2D field divided into rectangles of equal size. A simple grid. Some rectangles are empty space (and c...
When developing applications how much focus/time do you place on an application’s style vs. functionality. Battleship gray apps drive me insane. On the other hand maximizing a business application’s "style" can tax time and financial resources. Applications need to be appealing to resell or meet basic customer expectations, but defini...
I've realized I need a full-fledged browser automation tool for testing user interactions with our JavaScript widget library. I was using qunit, starting with unit testing and then I unwisely started incorporating more and more functional tests. That was a bad idea: trying to simulate a lot of user actions with JavaScript. The timing iss...
For anyone who's spent some time with sml, ocaml, haskell, etc. when you go back to using C, Python, Java, etc. you start to notice things you never knew were missing. I'm doing some stuff in Python and I realized what I really want is a functional-style datatype like (for example)
datatype phoneme = Vowel of string | Consonant of voice...
Let me establish that this is part of a class assignment, so I'm definitely not looking for a complete code answer. Essentially we need to write a converter in Scheme that takes a list representing a mathematical equation in infix format and then output a list with the equation in postfix format.
We've been provided with the algorithm t...
I have a set of custom ASP.NET server controls, most of which derive from CompositeControl. I want to implement a uniform look for "required" fields across all control types by wrapping each control in a specific piece of HTML/CSS markup. For example:
<div class="requiredInputContainer">
...custom control markup...
</div>
...
Given the Relation R with attributes ABCDE. You are given the following dependencies: A -> B, BC -> E, and ED -> A. I already have the answer which is CDE, ACD, and BCD. I just need to know how to do it. Thanks.
...
In my list, addition, the operation + appears as #. How can I make this appear exactly as +? When I eval it, it should also work exactly the same as +.
I guess this would also apply in all kinds of functions in Clojure...
Thanks guys.
...
When looking at F#, Ocaml and other functional language code examples I notice that the let keyword is used very often.
Why do you need it? Why were the languages designed to have it?
Why can't you just leave it out? e.g: let x=4 becomes x=4
...
having trouble changing an element of my function represented as a list.
code for random function:
(defn makerandomtree-10
[pc maxdepth maxwidth fpx ppx]
(if-let [output
(if (and (< (rand) fpx) (> maxdepth 0))
(let [head (nth operations (rand-int (count operations)))
children (doall (loop[function (list)
width...
Hello all,
I've been thinking of this question very long, but really couldn't find the answer on Google as well a similar question on Stackoverflow. If there is a duplicate, I'm sorry for that.
A lot of people seem to say that writing compilers and other language tools in functional languages such as OCaml and Haskell is much more effi...
Why won't this compile?
#include <functional>
#include <boost/function.hpp>
class A {
A() {
typedef boost::function<void ()> FunctionCall;
FunctionCall f = std::bind1st(std::mem_fun(&A::process), this);
}
void process() {}
};
Errors:
In file included from /opt/local/include/gcc44/c++/bits/stl_func...
Today we had a discussion at the office about UI elements in the required document.
the question is of a UI requirement is functional of non-functional.
"the background must be blue"
is this a functional or non-functional requirement?
...
I'm trying to implement sieve of Eratosthenes in Clojure. One approach I would like to test is this:
Get range (2 3 4 5 6 ... N)
For 2 <= i <= N
Pass my range through filter that removes multiplies of i
For i+1th iteration, use result of the previous filtering
I know I could do it with loop/recur, but this is causing stack overflow...
I have this implementation of the sieve of Eratosthenes in Clojure:
(defn sieve [n]
(loop [last-tried 2 sift (range 2 (inc n))]
(if
(or (nil? last-tried) (> last-tried n))
sift
(let [filtered (filter #(or (= % last-tried) (< 0 (rem % last-tried))) sift)]
(let [next-to-try (first (filter #(> % last-tried) ...
I realize this is a ludicrous question for something that takes less than 2 seconds to implement. But I vaguely remember reading that one was introduced with the new standard.
I grep'ed VC10's headers and came up with nothing. Can you help? It's bugging me! :)
edit:
On second thought, the new functor I was remembering was probably the ...
I've got the following problem: I have a tree of objects of different classes where an action in the child class invalidates the parent. In imperative languages, it is trivial to do. For example, in Java:
public class A {
private List<B> m_children = new LinkedList<B>();
private boolean m_valid = true;
public void invalidat...
I have a 3-rd party java application (I don't own source code) and I want to perform functional testing on it, similar to the way it's done in watin/watij/selenium/nunitforms etc. Can anyone suggest a library that I can use to do this sort of testing. What I'm interested in is clicking the applet's buttons, reading off text values, and t...
This is very similar to another question (Functional Data Structures in Java) but the answers there are not particularly useful.
I need to use immutable versions of the standard Java collections (e.g. HashMap / TreeMap / ArrayList / LinkedList / HashSet / TreeSet). By "immutable" I mean immutable in the functional sense (e.g. purely fun...