Tagged Questions

Functional programming is a programming paradigm which primarily uses functions as means for building abstractions and expressing computations that comprise a computer program.

learn more… | top users | synonyms (1)

0
votes
0answers
7 views

Removing duplicates in list results with unneeded tail

I want to remove all duplicates from a given list . Consider the following code : % check if the given element is in the given list member(Element,[Element|_]). ...
0
votes
2answers
17 views

SCHEME - Writing my own append produces a weird result

I want to write my own append , for appending an element to an existing list . I've written the following : (define (appendElem llist elem) (if (null? llist) elem (cons (car ...
2
votes
2answers
38 views

Why ocamlc says I mismatched {} while I don't?

I have written myPercolation.ml. open MyUnionFind module type MyPercolationSig = sig type percolation val create_percolation : int -> percolation val open_site : percolation -> int -> ...
0
votes
1answer
17 views

Can't load batteries using FindLib in Ocaml TopLevel

I successfully installed ocaml-batteries-included and findlib. I can do 'ocamlfind ocamlc -package batteries -c mycode.ml` without problems. Also, if I do ocamlfind list, I get $ ocamlfind list ...
0
votes
2answers
80 views

scala functional quick sort

In the chapter 2 of the book http://www.scala-lang.org/docu/files/ScalaByExample.pdf, M. Odersky wrote following implementation of quick sort def sort(xs: Array[Int]): Array[Int] = { if (xs.length ...
1
vote
2answers
26 views

Scheme let statement

In scheme which is a functional programming language, there is no assignment statement. But in a let statement (let ((x 2)) (+ x 3)) You are assigning 2 to x, so why doesn't this violate the ...
1
vote
1answer
21 views

Looking for a way to refactor D3.js-style method chaining pattern

While learning D3.js, I have come across the blog post explaining the main design-pattern behind it's reusable units of code. I have reproduced the relevant bit of code below. The way the pattern is ...
0
votes
2answers
45 views

Functional programming and the closure term birth

I'm studying functional programming and lambda calculus but I'm wondering if the closure term is also present in the Church's original work or it's a more modern term strictly concerned to programming ...
2
votes
1answer
52 views

Is it possible to pass the result of a function as input into two functions in Clojure?

I have the function generate-code that runs in a while loop in Clojure: ; ... (with-local-vars [code nil] (while true (var-set code (generate-code @code)) (write-to-file @code) ...
0
votes
1answer
35 views

SML - Build a new list with the elements of the original list - Error: operator and operand don't agree [literal]

Given a list of numbers , I want to create a new list where the element at index i is the sum of all the i-1 elements before . For example : [1,4,6,9] -> [1,5,11,20] I've written the ...
1
vote
2answers
38 views

Clojure fails when calling amap on a primitive array

On ClojureDocs, it mentions that aset is only workable on array of refrence java types. But it does not mentions about the usage of amap. (reduce (fn [#^doubles sum #^doubles prob] (println ...
4
votes
2answers
71 views

Which way of these two pattern matching is more preferred?

I'm just curious, these two functions would do the same thing. But which one should I use? let f a = match a with b -> a;; let f a = match a with b -> b;; Or it just ...
1
vote
1answer
38 views

Why does pattern with variable not match?

I'm writing a code that can find the median of a list, and I cannot use rec and should use List.fold_left/right. I wrote the following code, which should work. It finds the length of the list, if ...
2
votes
1answer
49 views

How to use lambda as lexical scope in C++

The codes are like this: int a = 1; auto f = [a] {return a;}; a = 100; std::cout << f() << endl; return 0; I expected to see 100 as the result. However, the a is like freezed when ...
1
vote
1answer
65 views

Is there an efficient algorithm to find which composition of boolean functions will match the output of a given boolean function?

Suppose I have the following boolean functions. def Bottom(): return False def implies(var1, var2): if var1 == True and var2 == False: return False return True def land(var1, var2): ...
0
votes
1answer
42 views

(sml) Syntax error?

I have this function that checks a list of parsers if they work or not. I get error: EQUALO LPAREN FN. Any help? fun oneOf [] = fn inp => NONE | oneOf (p::ps) = (fn inp => case parse p inp of ...
0
votes
1answer
25 views

How to know if the user is online providing only the username/nick/participant but not the whole JID (Ejabberd)

I am customising module mod_muc_room and I would like to add a function that knows if the user is online but only providing the username. In the module I can find the function is_user_online: ...
0
votes
1answer
40 views

JavaScript: Anonymous vs Helper function

I'm trying to understand this functional style code from the book Eloquent Javascript: http://eloquentjavascript.net/chapter6.html#exercise1 When the count() function passes an anonymous function to ...
0
votes
1answer
48 views

(sml/nj) Correct type?

For my assignment I have to do two functions with the type: wt: trie -> (char list list -> ’a)-> ’a aw: trie list -> (char list list -> ’a)-> ’a but what I have is this and was ...
1
vote
2answers
60 views

Strange module loading issue in OCaml

I have two files: myUnionFind.ml and myUnionFind_test.ml. Both files are in the same directory. myUnionFind.ml open Batteries module type MyUnionFindSig = sig type union_find val print_array ...
0
votes
4answers
70 views

Reduce set with lambda

Given a set where each element is a string, how can I reduce the set into an integer that is the sum of the length of these strings? setA = ("hi", "hello", "bye") reduce(lambda .... for word in setA) ...
1
vote
1answer
127 views

Idiomatic Scala to iterate over all substrings [closed]

Something less imperative than this: def subs(s: String) = for {start <- 0 to s.length; end <- i to s.length} yield s.substring(start, end)
6
votes
3answers
219 views

Tail Recursive Levenshtein Distance

I implemented Levenshtein Distance in a pretty standard way in F# as an exercise let lastchar (s:string) = s.Substring(s.Length-1, 1) let lastchar_substring (s:string) len = s.Substring(len-1, 1) ...
2
votes
2answers
74 views

Is there any operator.unpack in Python?

Is there any built-in version for this def unpack(f, a): return f(**a) #or ``return f(*a)'' Why isn't unpack considered to be an operator and located in operator.*? I'm trying to do something ...
1
vote
2answers
33 views

Disjunction distribution property in lisp [closed]

Basically I need to represent this property down below as a function in lisp (p and q) or (r and t) = (p or r) and (p or t) and (q or r) and (q or t) The function distribute-or (fbf) takes as an ...
1
vote
2answers
61 views

In OCaml, When to use Interface (mli) and when to use module?

OCaml provides mli for interface and a module system. My question is simple, how to choose from them?
1
vote
1answer
56 views

Why are there primitive functions like DoubleFunction in Java 8

I just had a look at the the new Java 8 function package and wonder why there are interfaces like DoubleFunction IntFunction LongFunction ... which do not extend Function. Doesn't that mean I will ...
2
votes
2answers
107 views

Simplest way to solve a maze without mutability

After learning some Scala and the benefits of FP, I am reimplementing some of my previous CS assignments to better understand FP. However, I got to one assignment that seems impractical to implement ...
2
votes
2answers
37 views

Extract object attribute from list of objects in Javascript

I have the following object that I'm receiving from an API: { '2012-12-12': [ { 'id': 1234, 'type': 'A' }, { 'id': 1235, 'type': 'A' }, { 'id': 1236, ...
1
vote
1answer
45 views

Rails: Functionals Test fails for undefined method in view

I'm new of Rails and I have a problem with a functional test that fails for undefined method in view : 1) Error: test_should_get_index(OrdersControllerTest): ActionView::Template::Error: undefined ...

1 2 3 4 5 120
15 30 50 per page