All Questions
Tagged with functional-programming clojure
22 questions
37
votes
7
answers
9k
views
What are the functional equivalents of imperative break statements and other loop checks?
Let's say, I've the below logic. How to write that in Functional Programming?
public int doSomeCalc(int[] array)
{
int answer = 0;
if(array!=null)
{
for(...
21
votes
3
answers
7k
views
Does Clojure have continuations/coroutines/etc?
I started programming with Python, and I was really confused by concepts like coroutines and closures.
Now I think I know them on some superficial level, but I've never felt that "enlightement" ...
12
votes
1
answer
8k
views
Pattern matching in Clojure vs Scala
What are the key differences between pattern matching in these two languages? I am not referring to syntax, but capability, implementation details, range of use cases and necessity.
Scala ...
1
vote
2
answers
878
views
How Functional Programming addresses concurrent increment/decrement operations invoked by different users?
Using Functional language, How can 2 different parties achieve the result of increment/decrement operations concurrently?
For the below scenario,
Let's say, I've 2 quantities in stock and 2 users in ...
2
votes
3
answers
914
views
Can functional programming used for solving problems which require randomness?
This older question tells us that in functional programming "true" randomness cannot be achieved since in FP functions are pure/idempotent and return the same value irrespective of number of ...
9
votes
3
answers
5k
views
How do people get rid of conditional branches in Functional Programming?
Long running switch cases or if-else-if constructs are avoided in OOP using polymorphism wherever it is applicable.
instead of branching by matching a value, branching is done at class-level itself.
...
3
votes
2
answers
283
views
Should I provide partialed functions based on API call in Clojure?
I am designing a library to wrap an API with Clojure. The API requires user credentials to authenticate user related calls.
My first approach was to have functions that do each task the API can do:
(...
-3
votes
2
answers
137
views
How can we handle inserts/delete cases using Map like data structures in FP?
Let's say, that we keep track of students entering the auditorium using their IDs(Key) and their check-in time(Value) in a Map. We delete the entries once they move out of the auditorium. I want to ...
13
votes
2
answers
4k
views
Could we build a functional computer?
As mush as FP has done, in the end, all our programs are structured.
That is, it doesn't matter how pure or functional we make a them - they are always translated to assembly,
so what actually runs ...
12
votes
3
answers
4k
views
Why can't we write nested shorthand functions in Clojure?
I tried to evaluate a Clojure expression with nested shorthand functions today, and it wouldn't let me.
The expression was:
(#(+ % (#(+ % (* % %)) %)) 5) ; sorry for the eye bleed
The output was:
...
26
votes
3
answers
2k
views
Why do some functional languages need software transactional memory?
Functional languages, by definition, should not maintain state variables. Why, then, do Haskell, Clojure, and others provide software transactional memory (STM) implementations? Is there a conflict ...
10
votes
2
answers
2k
views
Is Haskell/Clojure actually unsuited for dynamic systems such as particle simulation?
I've been told in previous questions that functional programming languages are unsuited for dynamic systems such as a physics engine, mainly because it's costly to mutate objects. How realistic is ...
7
votes
1
answer
2k
views
How to refactor a Java singleton to Clojure?
I'm writing a simple game in Java and I want to learn Clojure, so I've decided to refactor my current Java code to Clojure. The problem is that I've coded so much in object-oriented languages that I ...
7
votes
2
answers
504
views
How to represent hard-to-calculate "properties" of "objects" in functional code?
I have a polyline "class" in my Clojure program, which is represented by a vector of points. (It's not really a class or anything.)
The polyline's length (in the geometric sense) is something that is ...
11
votes
3
answers
2k
views
Scala or Clojure Functional Programming best practices
I did a lot of self-study coding, got some experience with Parallel Programming Models: Actors, Software Transactional Memory, Data Flow.
When I am trying to apply these architectures to real life - ...