Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [functional-programming]

Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the program state. In this style of programming, side effects and mutable data are deprecated.

1
vote
1answer
602 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 be ...
5
votes
2answers
289 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 ...
4
votes
1answer
195 views

First Common Lisp vector math code

I'm studying Common Lisp on my own. Coming from C++, Common Lisp feels kind of strange sometimes. I'd like to get some feedback on what I understood so far. For learning purposes, I wrote this simple ...
1
vote
1answer
213 views

Optimize this Scheme-written chess engine module

I'd like to know how to optimize this by shadowing symbols 'lo and 'hi inside nested function f. I guess CPS conversion would solve this but how? ...
10
votes
2answers
593 views

Naive Bayes classifier

I just started learning Haskell, and I must say it is unlike anything else. As my first not-entirely-trivial piece of code I tried to write a simple Bayes Classifier. It is in two parts, a classifier ...
11
votes
1answer
366 views

Concatenative PostScript library

As a part of picking up concatenative programming, I decided to implement the common concatenative operations in PostScript. Here is my attempt at implementing some of the words in other concatenative ...
7
votes
1answer
732 views

Clojure TicTacToe (logic, no GUI)

I whipped this up last night and was wondering if anyone had any thoughts/comments on it; for example, on: Code organisation Coding style Other improvements Semantic errors ...
2
votes
1answer
970 views

Defining transpose on a collection of irregular collections

I was asked to submit my request for code review on https://stackoverflow.com/questions/10672046/defining-transpose-on-a-collection-of-irregular-collections here. This is a follow-up to the post I ...
18
votes
2answers
6k views

Replacing Python Classes with Modules [closed]

I try to avoid using classes in Python as much as possible; if I don't plan on building on it, I don't build it in the first place. It helps me avoid Java-like classes like ...
4
votes
2answers
1k views

How do I dynamically create Python unit tests in a readable way?

I have Django unit tests that are pretty much the following format: ...
12
votes
1answer
1k views

Responsive/adaptive website code

I have all these functions that work together to create functionality on a page. Is the structure of these functions OK? Can I do anything to speed this up or make my code better? I'm not exactly ...
3
votes
2answers
159 views

Attempting to eliminate var (and imperative style) from my Piece class

I've been cooking with gas since I got Daniel C Sobral's help on my last question. I am now re-reading Odersky's "Programming in Scala, 2nd Edition" (finished my first reading about this time last ...
7
votes
1answer
920 views

F# Djikstras shortest path implementation

I'm just getting my feet wet with F#, by implementing some simple algorithms. First up: Djikstras shortest path. There is one piece I've written in this code which confuses me as to why it works: the ...
3
votes
1answer
1k views

Basic neural network

I just programmed a basic neural network in F# to learn the logical OR function. As I am very new to F# and especially functional programming, I did it the imperative way. And even tho it works, I ...
2
votes
1answer
127 views

Ideal FP/Scala way to vaildate rectangular list

I am learning Scala and FP (Functional Programming), coming from Java, OO and a strong imperative pardigm. I am now trying to implement a small puzzle solving project so I can get some deeper hands on ...
4
votes
1answer
667 views

Simple Haskell key value file store

As an exercise in learning Haskell, I implemented a simple key value store, where you can put and get values (as ByteStrings). (For reference this is inspired by ...
5
votes
3answers
1k views

Design pattern for adapter

I wrote a framework and I want to hear the thoughts of other on the design patterns it uses. Every method contains three design patterns - adapters(strategy), intercepting filters, and observers. A ...
4
votes
1answer
497 views

Project Euler question 2 in CoffeeScript

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. ...
21
votes
1answer
4k views

Java monad implementation

I'm learning functional programming and their concept of Monads. I've found nothing more effective in learning than writing an implementation in a programming language I have experience with. I came ...
8
votes
4answers
617 views

Printing a factorial from an integer

I am very new to functional programming. I wrote this program where the user can enter an integer and it will print the factorial. If the user enters a negative integer or not an integer at all, it'll ...
7
votes
4answers
761 views

Finding the sum of all the multiples of 3 or 5 below 1000, using list comprehension

I'm trying to compare my own implementation with another solution of Project Euler problem #1, which uses a list comprehension: ...
1
vote
1answer
2k views

Extending string mapping

Basically I'm trying to generalise and extend the notion of mapping one string into another. There are two methods I often find myself using for this: Functions, and Dictionairies. So here are my 3 ...
5
votes
3answers
378 views

Finding the first stream of non-repeating elements in Scala (without recursion or side-effects)

Here are some examples: [1, 2, 3, 4, 5] => [1, 2, 3, 4, 5] [10, 15, 10, 15, 30] => [10, 15] [1, 2, 3, 4, 1, 5, 6, 7] => [1, 2, 3, 4] Here's my best (and ...
2
votes
1answer
283 views

Scala object-function balance

I am learning Scala, coming from Java background. Here I have written a small prototype proof of concept program that is a part of concept base for a simple upcoming tutorial game. There are two game ...
6
votes
1answer
143 views

Chaining method calls and “bubbling” the results

I need a way to build up a sort of stack of places to search for an item. What I would like to do is to have each layer searched for an item, and if it is found at that level, then it should be ...
3
votes
3answers
163 views

Handler for a control to pan a map in four directions

I have a pan control that look like this: Pretty standard Google Mapsish controls, IMO. When the user clicks in the top 3rd of the control, it should pan up (deltaY = +1); right third means it ...
4
votes
1answer
707 views

Functionally retrieving rows from a database in Scala

Consider the following piece of code: ...
15
votes
0answers
151 views

Timeoutable computations module

Defines a simple module for timeoutable computations, with the ability to return arbitrary intermediary results on timeout or the final value otherwise. It also allows default return values. The ...
2
votes
4answers
5k views

Calculating a base price with surcharge conditions

The following code has a lot of conditionals. I am trying to write it in a functional programming way. ...
1
vote
2answers
1k views

Replacing a for loop that iterates over an array with the functional programming equivalent

How would I accomplish the same thing in a functional paradigm? ...
5
votes
2answers
546 views

Enclosing Circle Problem implementation in Haskell

I implemented the algorithm by Pr. Chrystal described here in Haskell so could someone please tell me: Do i have implemented this algorithm correctly? Initial calling of findPoints takes the first and ...
2
votes
2answers
563 views

Scala mastermind solver, which is the most scala-ish

I am trying to express the classical TDD kata of mastermind in the most idiomatic scala I can. Here is a scalatest, test suite : ...
8
votes
1answer
667 views

Deleting from Red Black Tree in F#

Yes I'm very slowly making my way through Purely Functional Data Structures. So I went through the section on Red Black Trees. What he presents is amazingly concise, except for the fact that he didn't ...
4
votes
1answer
192 views

Most elegant approach to writing list renumbering function

I'm writing a function with the following signature: (Ord a) => [a] -> [Int] It's semantics is to find an order-preserving mapping from list of objects to ...
6
votes
5answers
428 views

Is this good approach to use debug functions for implementing features?

Just thinking if using code like this ...
4
votes
1answer
347 views

Processing a tab-delimited file with vertexes and ages

The following block of code needs to be as fast as possible as it likely to be called many thousands of times in a run. I am also conscious that my thinking style is leaning towards a more procedural ...
4
votes
3answers
3k views

Generating permutations and combinations

How can this code be improved? ...
14
votes
1answer
570 views

Converting simple markup to HTML

This is going to be rather long and generic, so apologies in advance. I've been reading a lot about Haskell lately, but I've never really programmed anything with it beyond simple experiments in ghci....
36
votes
5answers
3k views

Sorting strings by length - functional Python

I'm trying to port this little F# snippet while staying pythonic: ...
5
votes
1answer
403 views

How can I make this F# more functional?

I am currently learning myself a little F# and have written the following code to practice. The code uses the Mono.Cecil library to inject some IL at the start of every method in each .net assembly ...
7
votes
2answers
993 views

Erlang code to list all IP addresses

This is some Erlang code I wrote to output a string of all the IP addresses of the machine. The string is simply printed to the user for him to read. ...
10
votes
1answer
512 views

Getting the last date where a given week day occurred

I'm trying to learn a little bit about functional programming and as my tool I chose F# since I'm a .NET developer and the environment is more natural to me. In one of my pet projects I'm dealing ...
12
votes
3answers
506 views

Reservoir Sampling in Clojure

I am learning clojure and decided to start out by trying to write a solution to a fairly simple algorithm, reservoir sampling. As I stated, I am learning clojure specifically and problem solving in a ...
23
votes
3answers
2k views

Project Euler Problem 2 in Clojure

I am in the process of learning Clojure. I am fairly new to functional programming and would like to know if my code smells or if there are any performance implications with my approach. ...