I'm looking to make a callable JavaScript object, with an arbitrary prototype chain, but without modifying Function.prototype.
In other words, this has to work:
var o = { x: 5 };
var foo = bar(o);
assert(foo() === "Hello World!");
delete foo.x;
assert(foo.x === 5);
Without making any globally changes.
...
Hy,
I'm writing a class which should help me in unit tests. The class offers methods to perform Assertions on Exceptions.
Until now I was able to write methods which take a function with no parameters and no return value as input. To do this I use the System.Action - delegates.
My class looks like this:
internal static class Exceptio...
I know that in pure object-oriented languages like Java it usually makes sense to use ORMs like Hibernate. But what would I do when writing a CRUD-type functionality in Clojure or Common LISP?
Passing around SQL as the first-order functions? But isn't having SQL in HTML-generating code very ugly?
Thanks,
Olek
...
For those of you out there who are using f#, what areas of functionality are you coding with it? What is the language really well suited to and what does it do with far more power and ease than say c#?
...
I'm trying to find a way to do the following function with foldl:
count a = length (filter (\i -> i) a)
It just counts the number of values that are true in a list of booleans. I did try it myself with
count = foldl (\i ->
case i of
True -> (1+)
False -> (0+)
) 0
Which did not even compile. Any suggestion...
I'm currently teaching myself Haskell, and I'm wondering what the best practices are when working with strings in Haskell.
The default string implementation in Haskell is a list of Char. This is inefficient for file input-output, according to Real World Haskell, since each character is separately allocated (I assume that this means tha...
I just had a use case where I needed to split a list into n sublists, so that elements are taken in order from the original list and grouped while the predicate is true for the sublist (when it is false, a new sublist is started). I didn't find this functionality in the standard library, and I thought it was a good exercise to try to sol...
Hi all,
I've been trying to work my way through Problem 27 of Project Euler, but this one seems to be stumping me. Firstly, the code is taking far too long to run (a couple of minutes maybe, on my machine, but more importantly, it's returning the wrong answer though I really can't spot anything wrong with the algorithm after looking thr...
Which techniques or paradigms normally associated with functional languages can productively be used in imperative languages as well?
e.g.:
Recursion can be problematic in languages without tail-call optimization, limiting its use to a narrow set of cases, so that's of limited usefulness
Map and filter have found their way into non-fu...
I recently tried to use an implementation of map in javascript to create a bunch of items, then apply them to an objects add method.
Firstly with a bog standard implementation of map.
var map = function (fn, a)
{
for (i = 0; i < a.length; i++)
{
a[i] = fn(a[i]);
}
}
Setup.
var translateMenu = new Menu;
var langu...
I just ran into this while going through the Erlang compiler source.
I'm not really getting it. (go figure ;)), considering that I just realized that there is such a thing 5 minutes ago).
Forgive me for asking first without first trying to understand reasons for its existence.
There is a wikipedia article about it, but it is pret...
In Real World Haskell, there is a section titled "Life without arrays or hash tables" where the authors suggest that list and trees are preferred in functional programming, whereas an array or a hash table might be used instead in an imperative program.
This makes sense, since it's much easier to reuse part of an (immutable) list or tr...
Is there a way to construct a self-referential data structure (say a graph with cycles) in lisp or scheme? I'd never thought about it before, but playing around I can find no straightforward way to make one due to the lack of a way to make destructive modification. Is this just an essential flaw of functional languages, and if so, what a...
Higher order perl shows how to exploit functional programming features of perl. Is there a similar book for C#
...
My professor told us that we could choose a programming language for our next programming assignment. I've been meaning to try out a functional language, so I figured I'd try out clojure. The problem is that I understand the syntax and understand the basic concepts, but I'm having problems getting everything to "click" in my head. Doe...
One of the arguments I've heard against functional languages is that single assignment coding is too hard, or at least significantly harder than "normal" programming.
But looking through my code, I realized that I really don't have many (any?) use patterns that can't be written just as well using single assignment form if you're writing...
I am convinced that functional programming is an excellent choice when it comes to applications that require a lot of computation (data mining, AI, nlp etc).
But is it wise to use functional programming for a typical enterprise application where there are a lot of business rules but not much in terms of computation?
Please disregard ...
In C# how do I memoize a function with two arguments?
Do I have to curry before memoization?
Wes Dyer wrote the Memoization code I typically use, but now I need two arguments
...
I am having issues manipulating deeply nested lists in OCaml in the below context.
class foo (pIn:int)=
object (self)
val p = pIn
val even = if (pIn mod 2) = 0 then true else (false)
method doIt = "doIt"
method isEven = even
method getP = p
end;;
let rec createListOfElements howMany = (
Random.self_init ();
...
With all the hype around functional programming, which are the best resources to getting started in functional programming [for a C# programmer]? I am not looking for C# 3.0 language improvements.
...