12
votes
3answers
283 views
+50
Functional implementation of Tarjan's Strongly Connected Components algorithm
I went ahead and implemented the textbook version of Tarjan's SCC algorithm in Scala. However, I dislike the code - it is very imperative/procedural with lots of mutating states and book-keeping ...
1
vote
1answer
93 views
How do I rewrite (def) out of this Clojure code?
I have written a game loop based on deWitter's game loop.
However, I am unsure how to transfer it to a more functional state. I realize that there may need to be some mutable state left within the ...
2
votes
3answers
217 views
What are those functional functions called?
I'm looking for a functional way to implement this:
list = [a b c d e f]
foo(list, 3) = [[a d] [b e] [c f]]
A potential solution is:
foo(list,spacing) = zip(goo(list,spacing))
Where, for ...
0
votes
1answer
92 views
Partial and named arguments in Clojure
I'm a Python programmer just learning Clojure. In Python I love how I can used named arguments in a call to functools.partial:
def pow(base, exponent):
return base ** exponent
exp = ...
0
votes
1answer
67 views
How should I treat a functional programming language different from an imperative one? [closed]
After mainly focusing on Java, an imperative programming language from my understanding, I'm about to start learning Clojure. One difference is that Clojure is a functional programming language; what ...
5
votes
1answer
84 views
laziness does not work as expected
(defn seq-trial
[]
(map #(do (println "hello " %) (inc %)) (range 10)))
(take 3 (seq-trial))
The code snippt above when evaluated prints out the following -
(hello 0
hello 1
hello 2
hello ...
2
votes
2answers
63 views
Manipulating java objects from clojure
am new at clojure and would like to interact with java objects using clojure. If I have well understood,
one can reach this interaction using defprotocol.
What I concretely try to do is the ...
2
votes
2answers
73 views
Create and then write to a text file what is printed to the REPL
How, from a clj file, to take whats is outputted to the REPL by the function "print" and put it all in text file ?
Is there a way to create a new, empty, text file and put it in the project directory ...
1
vote
3answers
77 views
clojure how to know the path of a folder / file / directory in one project?
Assume there is two files inside my clojure project, one clj and the other is txt.
Is there a way to know the path (as a string) of the txt file from the clj file?
There is:
(System/getProperty ...
0
votes
1answer
48 views
update DB function clojure
i'm trying to build a function similar to SQL :
UPDATE Persons SET Address=Martin20, City=Miami WHERE LastName=Darmon AND FirstName=Gilad
i have parsed the SET and Where into a map and List.
and ...
1
vote
1answer
45 views
Clojure AND / OR of Sets
(defn GetValuesFromWhereCommand
"return a list of values from Where command"
[Query tableName]
(let [values (re-seq #"[0-9a-zA-Z_=<>]+" ((re-find #"WHERE(.*)" Query) 1))
...
4
votes
5answers
247 views
Best functional language to do MapReduce? [closed]
I'm doing an assignment for a course, which requires me to implement a parallel MapReduce engine in a functional language and then use it solve certain simple problems.
Which functional language do ...
2
votes
1answer
63 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)
...
1
vote
2answers
54 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 ...
2
votes
2answers
75 views
How to call original function when it's shadowed by binding?
I have such situation:
(defn a []
(do-something))
(defn b []
(let [original (a)]
(modify-original)))
(defn c []
(binding a b)
(a))
How can I "break binding" and call a in ...