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
vote
1answer
45 views

Scala: tail-recursive factorial

Is there anything what could be improved on this code? def factorial(n: Int, offset: Int = 1): Int = { if(n == 0) offset else factorial(n - 1, (offset * n)) } The idea is to have tail-recursive ...
2
votes
0answers
21 views

Counting Ways to Make Change — Is this good functional/Lisp style?

I have just started learning some Scheme this weekend. I recently solved a problem that goes something like: Count the number of ways possible to give out a certain amount of change using 1 5 10 25 ...
3
votes
2answers
83 views

Format names to title case

So I'm writing a program to format names to title case and display them in alphabetic order. Any advice please? And how can i add more methods? public static void main (String [] args) { ...
3
votes
1answer
80 views

Help make nested folds look less terse

My Haskell set/map/list folds often become terse and difficult to read. I'm looking for tips on how to make my functional code easier to follow. I'm working around a bug/feature in a plotting ...
10
votes
4answers
1k views

How to shorten this terrible code?

I am trying to read a line ending in \r\n from a Handle. This is an HTTP header. I’m fairly new to functional programming, so I tend to use a lot of case expressions and stuff. This makes the code ...
6
votes
3answers
152 views

Overusing JavaScript closures?

I've finally gotten around to learning Lisp/functional programming. However, what I've noticed is that I'm trying to bring ideas back into JavaScript. Example Before var myPlacemark, ...
3
votes
1answer
107 views

Connect Four: Bitboard checking algorithm

I'm rather new to Clojure and so I decided to program a Connect Four for fun and learning. The code below is a Clojure implementation of this bitboard algorithm. The whole code can be found here: ...
2
votes
0answers
56 views

simple stupid F# async telnet client

Did I write this code to correctly be tail call optimized? Am I forcing computations more than I need with !? Did I generally write this asynchronously correctly to allow sends and receives to occur ...
4
votes
2answers
99 views

Writing an infinitely running( while(true) { } ) user input function in haskell

I'm trying to implement a lexer in Haskell. For easy console input and output, I've used an intermediate data type Transition Table. type TransitionTable = [(Int, Transitions String Int)] type ...
2
votes
0answers
34 views

Calculate FFT from windowed time-based signal

I have a time-based signal (Raw signal) sampled at 6 MHz and need to analyze it in freq. domain. I'm learning DSP and this is very first time I work with DSP. Could you please help to check if this ...
2
votes
2answers
52 views

Looking for a functional collapse/group-by of this data in ruby

Can anyone come up with a functional (no mutating variables) way in ruby to do the following? Given this sorted data: data = [{1 => "A"}, {2 => "B"}, {3 => "B"}, {4 ...
5
votes
3answers
124 views

Scala: a safer way to cut string

I want to get just the first line of a big string. Currently, here's how I do it: def getFirstParagraph(txt: String) = { val newLineIdx = txt.indexOf("\n") match { case i: Int if i > 0 ...
1
vote
2answers
73 views

Safe composition in python

def json_response(response): assert response.code == 200, 'bad http response' return json.loads(response.body) def custom_json_response(response): response = json_response(response) ...
1
vote
1answer
70 views

Solution to 99 lisp problems: P08 with functional javascript

Solution to 99 lisp problems: P08, with functional javascript If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not ...
4
votes
2answers
154 views

Change code to use functional style

I tried to solve a programming contest problem in Scala, but I have a feeling, that it could be done in a more functional way. I compared it with the solution written in imperative style and it is not ...

1 2 3 4
15 30 50 per page