clojure-contrib

loading clojure-contrib

为君一笑 提交于 2020-01-04 02:34:34
问题 I'm new to the whole JVM thing, and trying to play with clojure. I'm attempting to load clojure-contrib and failing: # in bash $ java -cp /path/to/clojure.jar:/path/to/contrib.jar clojure.main # in REPL user=> (require 'clojure.contrib.math) nil user=> (sqrt 2) java.lang.Exception: Unable to resolve symbol: sqrt in this context (NO_SOURCE_FILE:10) Any pointers will be great - thanks. 回答1: I'm no expert, but it seemed like a namespace issue. The solution I employed was this: ;; for REPL user=>

How do I dynamically find metadata for a Clojure function?

ε祈祈猫儿з 提交于 2019-12-22 01:28:22
问题 Say I have the following code: (defn ^{:graph-title "Function 1"} func-1 [x] (do-something-with x)) (defn get-graph-title [func] (str ((meta func) :graph-title))) I expect this to return "Function 1", but it returns nil. I think this stems from the following difference, which I don't totally comprehend: (meta func-1) => {:ns some-ns-info, :name func-1} (meta #'func-1) => {:ns some-ns-info, :name func-1, :graph-title "Function 1"} Can someone explain this to me? 回答1: The metadata is attached

How does ClojureQL compare to clojure.contrib.sql?

主宰稳场 提交于 2019-12-20 09:35:04
问题 It looks like each one covers the basic cases like selecting certain columns and filtering by predicate pretty well, but I'm wondering how each compares for more advanced cases. Is it easier to express complex queries in one vis-à-vis the other? Is one library missing any functionality that the other covers? 回答1: ClojureQL and clojure.contrib.sql are two quite different libraries. The first aims to implement the primitives from relational algebra and compile those to SQL92. It also offer an

Equivalent to clojure.contrib's show?

限于喜欢 提交于 2019-12-14 00:19:47
问题 There used to be this useful utility called show in clojure.contrib. Now, that it's deprecated, is there an equivalent to it? Thanks! 回答1: De-constructing show to be more "simple", making available distinct pieces of re-usable functionality, was discussed by Stuart Halloway in a talk he give on clojure simplicity. The resulting code makes use of clojure.reflect/reflect and clojure.pprint/print-table and standard clojure filter : (require 'clojure.reflect) (require 'clojure.pprint) (->>

How to rewrite Ruby's `Array(x)` in Clojure?

瘦欲@ 提交于 2019-12-13 17:37:42
问题 In Ruby, there is Kernel#Array method, which acts like this: Array([1, 2, 3]) #=> [1, 2, 3] Array(1..5) #=> [1, 2, 3, 4, 5] Array(9000) #=> [9000] Array(nil) #=> [] In other words, it converts nil to empty array, non-collections to singleton arrays, and kinds of collection-like objects (i.e. objects which respond to #to_ary or #to_a ) to arrays. I want to have something similar to this in Clojure: (to-seq [1 2 3]) ;=> (1 2 3) (to-seq (range 1 5)) ;=> (1 2 3 4) (to-seq 9000) ;=> (9000) (to-seq

Raising elements in a vector to a power

谁都会走 提交于 2019-12-13 07:27:24
问题 I am trying to input a vector and parameter p, which in turn should raise each element of the vector to the power p. So far I have tried mapping the numeric tower function power, but that has proved unsuccessful. What would be the easiest way to raise each element of a vector to a power p? (defn p' [x p] (map power x p)) 回答1: You need something like: (defn compute [exp numbers] (map #(power exp %) numbers)) For more information, type the following in your REPL: (doc map) 回答2: To expand on

how do i get rid of duplicate clojure test-is unit tests on the REPL

南笙酒味 提交于 2019-12-11 02:13:55
问题 I have a little script (use :reload-all 'com.example.package1 'com.example.package2 'com.example.package3 'com.example.testlib) (run-tests 'com.example.package1 'com.example.package2 'com.example.package3) that I use to quickly reload everything and fire off the unit tests. trouble is that each time (deftest ... ) is evaluated as the files are read an additional test is created so after working hard all day each test is now being run 103 times, eek! 回答1: There is a flag *load-tests* which

IllegalStateException Compiling Clojure-Contrib

余生长醉 提交于 2019-12-07 01:13:44
问题 I am trying to compile my own version of clojure-contrib with Maven I get the following exception: Exception in thread "main" java.lang.IllegalStateException: Can't dynamically bind non-dynamic var: clojure.contrib.pprint/*format-str*, compiling:(dispatch.clj:90) I am also using the following command to compile it: mvn package -Dclojure.jar=/usr/local/share/jars/clojure.jar clojure.jar is link to the actual jar (that is on the same directory) because I am using a version that I compiled from

How do I dynamically find metadata for a Clojure function?

橙三吉。 提交于 2019-12-04 22:47:21
Say I have the following code: (defn ^{:graph-title "Function 1"} func-1 [x] (do-something-with x)) (defn get-graph-title [func] (str ((meta func) :graph-title))) I expect this to return "Function 1", but it returns nil. I think this stems from the following difference, which I don't totally comprehend: (meta func-1) => {:ns some-ns-info, :name func-1} (meta #'func-1) => {:ns some-ns-info, :name func-1, :graph-title "Function 1"} Can someone explain this to me? The metadata is attached to the var, not to the function. Thus, to get the graph title, you have to get the entry :graph-title from

Equivalent to clojure.contrib's show?

元气小坏坏 提交于 2019-12-04 04:28:33
There used to be this useful utility called show in clojure.contrib. Now, that it's deprecated, is there an equivalent to it? Thanks! De-constructing show to be more "simple", making available distinct pieces of re-usable functionality, was discussed by Stuart Halloway in a talk he give on clojure simplicity. The resulting code makes use of clojure.reflect/reflect and clojure.pprint/print-table and standard clojure filter : (require 'clojure.reflect) (require 'clojure.pprint) (->> (clojure.reflect/reflect java.lang.String) :members (filter #(.startsWith (str (:name %)) "last")) (clojure.pprint