iteration - How to iterate over a clojure eduction - without creating a seq?

For the sake of this question, let's assume I created the following eduction.(def xform (map inc))(def input [1 2 3])(def educt (eduction xform input))Now I want to pass educt to some function that can then do some kind of reduction. The reason I want to pass educt, rather than xform and input is that I don't want to expose xform and input to that function. If I did, that function could simply do a (transduce xform f init input). But as I don't, that function is left with an eduction that cannot be used with transduce.I know I can e.g. use dose...Read more

iteration - How to iterate over a clojure eduction - without creating a seq?

For the sake of this question, let's assume I created the following eduction.(def xform (map inc))(def input [1 2 3])(def educt (eduction xform input))Now I want to pass educt to some function that can then do some kind of reduction. The reason I want to pass educt, rather than xform and input is that I don't want to expose xform and input to that function. If I did, that function could simply do a (transduce xform f init input). But as I don't, that function is left with an eduction that cannot be used with transduce.I know I can e.g. use dose...Read more

clojure - lein repl :connect 7000 gives ConnectException Connection refused

When I just do lein repl it works, but when I try to connect to a host I get a refusing to connect error.Connecting to nREPL at 127.0.0.1:7000ConnectException Connection refused (Connection refused) java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2) java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:400) java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:243) java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:225) java.net.SocksSocketImpl.connect...Read more

clojure - How do I mock sqlKorma?

I am unfamiliar with how mocking works within Clojure. Specifically, I am unsure about how I should test a function which implements a sqlKorma query or call to the database? I would ideally like to be able to mock sqlKorma in my tests.(defn fetch [id](-> (korma/select* :my-table) (korma/where {:id id}) (korma/exec)))(defn retrieve [id] (-> (fetch id) (ring/response)))I am using Speclj to test my application. (describe "item" (it "is fetched" (let [fetched (fetch :test-case)] ;here I want to be able to mock s...Read more

clojure - Bubble sort for letters

I want to develop a bubble sort function that reorders letters into the correct order alphabetically. So far this is my code(defn bubble [ys x] (if-let [y (peek ys)] (if (> y x) (conj (pop ys) x y) (conj ys x)) [x]))(defn bubble-sort [xs] (let [ys (reduce bubble [] xs)] (if (= xs ys) xs (recur ys))))I believe the issue is the > on the line (if (> y x) and the = on the line (if (= xs ys). This makes it want a number and not a letter. Is their anyway I can change this code to make it work for letters?...Read more

clojurescript - How to use assoc-in to update multiple values in a map? (Clojure)

I am trying to update every line that has an "enjoy-clojure?" that returns true "sanity-rating" to -2 (i.e johnny's sanity-rating would be updated to -2)(def student-database { 0 {:enjoy-clojure? false, :name "jimmy",:sanity-rating 9} 1 { :enjoy-clojure? true, :name "johnny",:sanity-rating 2} 2 { :enjoy-clojure? true, :name "jilly",:sanity-rating 5} 3 { :enjoy-clojure? true, :name "janey",:sanity-rating 8} 4 {:enjoy-clojure? false, :name "jelly",:sanity-rating 10}}) I am new to Clojure and have tried researching update and assoc an...Read more

cider - "The clojure executable isn’t on your ‘exec-path’" even though lein is on my exec-path (macOS)

I have the following exec-path (according to describe-variable):("/usr/local/bin/" "/usr/bin/" "/bin/" "/usr/sbin/" "/sbin/" "/usr/local/Cellar/emacs-plus/25.3/libexec/emacs/25.3/x86_64-apple-darwin16.7.0/") This is the lein executable path:/usr/local/bin/leinThis is what happens when I run cider-jack-in:The clojure executable isn’t on your ‘exec-path’What gives?Edit: (cider-lein-command is lein)...Read more

clojure - Datomic entity-api is slow on large amount of entities?

I need to apply additional logic (like mapping, conditionals, aggregating) to entities I get from Datomic. I had hard time translating it to Datomic query (I'm not sure if it's even possible in my case), which is why I used datomic's raw index access instead, so the most work and logic is done in Clojure.It worked fine until I got to ~500K entries and the whole approach is getting very slow.The relevant code:(defn e->entry "Map e into entry" [e] {:id (:entry/uuid e) ;; each flat field increases mapping time (seems linearly) :date (:...Read more

Clojure multimethods vs. protocols

I'm a Clojure novice and was looking for some concrete examples of when to use protocols and when to use multimethods. I know that protocols are generally geared towards creating a type hierarchy and typical OOP things, that they were added to the language after multimethods, and that protocols generally have better performance so my question is this:Are protocols meant to replace multimethods? If not, could you give me an example where I would use multimethods instead of protocols?...Read more

How do you make a web application in Clojure?

I suppose this is a strange question to the huge majority of programmers that work daily with Java. I don't. I know Java-the-language, because I worked on Java projects, but not Java-the-world. I never made a web app from scratch in Java. If I have to do it with Python, Ruby, I know where to go (Django or Rails), but if I want to make a web application in Clojure, not because I'm forced to live in a Java world, but because I like the language and I want to give it a try, what libraries and frameworks should I use?...Read more

iteration - Clojure lazy-seq over Java iterative code

I'm trying to use create a Clojure seq from some iterative Java library code that I inherited. Basically what the Java code does is read records from a file using a parser, sends those records to a processor and returns an ArrayList of result. In Java this is done by calling parser.readData(), then parser.getRecord() to get a record then passing that record into processor.processRecord(). Each call to parser.readData() returns a single record or null if there are no more records. Pretty common pattern in Java.So I created this next-record funct...Read more

clojure - Why exactly is eval evil?

I know that Lisp and Scheme programmers usually say that eval should be avoided unless strictly necessary. I’ve seen the same recommendation for several programming languages, but I’ve not yet seen a list of clear arguments against the use of eval. Where can I find an account of the potential problems of using eval?For example, I know the problems of GOTO in procedural programming (makes programs unreadable and hard to maintain, makes security problems hard to find, etc), but I’ve never seen the arguments against eval.Interestingly, the same ar...Read more

Clojure: reduce vs. apply

I understand the conceptual difference between reduce and apply:(reduce + (list 1 2 3 4 5)); translates to: (+ (+ (+ (+ 1 2) 3) 4) 5)(apply + (list 1 2 3 4 5)); translates to: (+ 1 2 3 4 5)However, which one is more idiomatic clojure? Does it make much difference one way or the other? From my (limited) performance testing, it seems reduce is a bit faster....Read more

clojure - conda, condi, conde, condu

I'm reading the Reasoned Schemer.I have some intuition about how conde works.However, I can't find a formal definition of what conde/conda/condu/condi do.I'm aware of https://www.cs.indiana.edu/~webyrd/ but that seems to have examples rather than definitions.Is there a formal definition of conde, conda, condi, condu somewhere?...Read more