clojure

“No matching ctor found” while trying to populate a Java class from Clojure

删除回忆录丶 提交于 2020-01-01 09:23:43
问题 I am getting a "No matching ctor found" error while trying to populate a Java class from Clojure. I want to populate this class from Clojure. import java.util.Date; public class Account { Account() { acct_num = 0; trans_type = 'U'; trans_amt = 0.00; cur_bal = 0.00; last_update = null; } public int acct_num = 0; public char trans_type; public double trans_amt = 0.00; public double cur_bal = 0.00; public Date last_update; } I can import the class: ba2-app=> (ns ba2-app (:import Account))

What is the difference between an atom in Common Lisp and an atom in Clojure?

纵然是瞬间 提交于 2020-01-01 08:25:12
问题 The following page talks about how atoms work in Clojure. It doesn't say a whole lot about the differences between atoms in Clojure and other lisp dialects. What is the primary difference between an atom in Common Lisp and an atom in Clojure? (What is missing from the definition of atom in Clojure that exists in CL?) 回答1: Atoms in Clojure and atoms in Common Lisp (and most other Lisps) are two completely unrelated concepts. They have nothing to do with each other, other than having the same

Manage dependencies in `project.clj` from the command line

假如想象 提交于 2020-01-01 05:59:05
问题 I would like to search and install clojure dependencies from the commandline. Does there exists a tool/leiningen command/ lein change script?/... that can: search for clojure libraries online rewrite project.clj to include the dependency (latest version) update dependencies? Much along the lines of npm install --save ( --save-dev ) and npm search , for those that are familiar with npm (JS/Node package manager). (Maybe boot provides a more npm-like workflow?) 回答1: You could find complete list

Idiomatic Clojure to copy resources from running jar to outside

寵の児 提交于 2020-01-01 05:21:07
问题 It seems like a classical problem but I can't find anything about it "the clojure way". So, I have a foo/ directory inside resources/ (leiningen project). When jar'd/uberjar'd, this foo/ directory is put at the root of the jar. As files inside jar may not be physically consistent at runtime, you can't use basic copy function to recursively copy the directory to the outside world. Several solutions for the Java world exist (How to write a Java program which can extract a JAR file and store its

Clojure code static analysis tools

北城余情 提交于 2020-01-01 04:53:21
问题 Is there a tool to run code convention tests in clojure? For example, make sure function names don't have any capital letters or keywords don't have any underscores in them. 回答1: Two useful Leiningen plugins I learned about recently: lein-bikeshed lein-kibit 回答2: Late to the party here. Seconding noahlz, the three main static analysis tools that I use on a regular basis are lein-bikeshed, lein-kibit, and Eastwood, though I also use yagni. Each of these has different strengths. Bikeshed is

How to write monoid protocol in Clojure?

孤人 提交于 2020-01-01 04:43:15
问题 The following does not work, for obvious reasons. (defprotocol Monoid (mappend [a b]) (mzero [])) mzero has zero arguments, and zero argument methods are not allowed (or do not make sense) in protocols. In Haskell or Scala, where the dispatch is type-based rather than value-based, this is not a problem. What would be the correct way to conceptualize and write Monoid protocol in Clojure? 回答1: looking at the source, the way that this is implemented in the new reducers library is not as a

get a clojure function's code

不问归期 提交于 2020-01-01 04:20:08
问题 Is there a way in clojure to get a function's code after the function has been loaded? Ie. without doing something like [untested] (defmacro blat [x] `(do (def code ~(quote (mexpand-all x))) ~x))) (blat (defn func [abc] (...))) 回答1: You can get the source of a symbol using the clojure.repl/source function. However, this only works if the var for which the symbol resolves to is in a .clj file on the classpath. You can't, for example, do this: user=> (defn foo [x] x) #'user/foo user=> (require

How can I determine number of arguments to a function in Clojure?

廉价感情. 提交于 2020-01-01 04:07:12
问题 Given a function x in clojure how can I programatically get a count of the number of arguments? eg: (fn a [b c] ...) has has two arguments (fn a [] ...) has has zero arguments 回答1: If you have access to the var that holds the function you can get the argument count by accessing its metadata in the following way: (defn arities [v] (->> v meta :arglists (map count))) (defn a []) (defn b [_ _]) (map arities [#'a #'b]) ;= ((0) (2)) arities will return a seq with all the arities for the function.

How can I determine number of arguments to a function in Clojure?

╄→尐↘猪︶ㄣ 提交于 2020-01-01 04:07:06
问题 Given a function x in clojure how can I programatically get a count of the number of arguments? eg: (fn a [b c] ...) has has two arguments (fn a [] ...) has has zero arguments 回答1: If you have access to the var that holds the function you can get the argument count by accessing its metadata in the following way: (defn arities [v] (->> v meta :arglists (map count))) (defn a []) (defn b [_ _]) (map arities [#'a #'b]) ;= ((0) (2)) arities will return a seq with all the arities for the function.

Can you formulate the insertion sort as a monoid in Clojure?

旧时模样 提交于 2020-01-01 03:37:15
问题 This is the code for an insertion sort in Clojure: (defn in-sort! [data] (letfn [(insert ([raw x](insert [] raw x)) ([sorted [y & raw] x] (if (nil? y) (conj sorted x) (if (<= x y ) (concat sorted [x,y] raw) (recur (conj sorted y) raw x )))))] (reduce insert [] data))) ;Usage:(in-sort! [6,8,5,9,3,2,1,4,7]) ;Returns: [1 2 3 4 5 6 7 8 9] This is the insertion sort formulated as a monoid in Haskell: newtype OL x = OL [x] instance Ord x => Monoid (OL x) where mempty = OL [] mappend (OL xs) (OL ys)