clojure

Why can't I use Clojure's :^const with a Java byte array?

只谈情不闲聊 提交于 2019-12-23 07:36:51
问题 Using lein repl with Clojure 1.4.0, I can define a ^:const of a Java byte array, but I can't then do anything with it: user=> (def x (byte-array (map byte [0 1 2 3]))) #'user/x user=> (alength x) 4 user=> (type x) [B user=> (def ^:const cx (byte-array (map byte [0 1 2 3]))) #'user/cx user=> (alength cx) CompilerException java.lang.RuntimeException: Can't embed object in code, maybe print-dup not defined: [B@10e6cbd, compiling:(NO_SOURCE_PATH:1) user=> (type cx) CompilerException java.lang

Can I make a Deterministic Shuffle in clojure?

你离开我真会死。 提交于 2019-12-23 07:29:51
问题 I'd like to make some shuffles of sets which will be the same every time my program is run: This is one way to do it: (def colours ["red" "blue" "green" "yellow" "cyan" "magenta" "black" "white"]) (defn colour-shuffle [n] (let [cs (nth (clojure.math.combinatorics/permutations colours) n)] [(first cs) (drop 1 cs)])) ; use (rand-int 40320) to make up numbers, then hard code: (def colour-shuffle-39038 (colour-shuffle 39038)) (def colour-shuffle-28193 (colour-shuffle 28193)) (def colour-shuffle

Clojure web framework for designers/ front end devs [closed]

寵の児 提交于 2019-12-23 07:29:35
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . All of the popular Clojure web frameworks I am seeing use hiccup to generate HTML. I find hiccup is hard to have a front end design person adjust to, compared to other frameworks that parse the syntax out of templates. Is there a clojure web framework that doesn't require the front end developer to learn LISP?

Why does `vector` implementation have multiple cases?

南笙酒味 提交于 2019-12-23 07:27:58
问题 Here's clojure's definition of vector: (defn vector "Creates a new vector containing the args." {:added "1.0" :static true} ([] []) ([a] [a]) ([a b] [a b]) ([a b c] [a b c]) ([a b c d] [a b c d]) ([a b c d & args] (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d args)))))))) Why are there so many cases? Or, if there are so many, why aren't there more? My guess is that it's striking a balance between implementation efficiency and probability, but I don't quite see

How to invoke superclass' method in a Clojure gen-class method?

亡梦爱人 提交于 2019-12-23 07:25:22
问题 I'm trying to create a class that extends input stream Clojure via gen-class . If I want to invoke the parent class' method, how do I do that? 回答1: From (doc gen-class) 1 : :exposes-methods {super-method-name exposed-name, ...} It is sometimes necessary to call the superclass' implementation of an overridden method. Those methods may be exposed and referred in the new method implementation by a local name. So, in order to be able to call the parent's fooBar method, you'd say (ns my.custom.Foo

In the clojure source code, what does RT stand for?

五迷三道 提交于 2019-12-23 06:58:36
问题 clojure / src / jvm / clojure / lang / RT.java The above seems to be one of the most important source files in clojure source code. For the sake of understanding the architecture, what does the RT stand for? 回答1: RT stands for Run-time. 来源: https://stackoverflow.com/questions/5980119/in-the-clojure-source-code-what-does-rt-stand-for

Clojure: Unable to find static field

…衆ロ難τιáo~ 提交于 2019-12-23 06:56:58
问题 Given the following piece of code: (map Integer/parseInt ["1" "2" "3" "4"]) Why do I get the following exception unless I wrap Integer/parseInt in an anonymous function and call it manually ( #(Integer/parseInt %) )? clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to find static field: parseInt in class java.lang.Integer 回答1: the documentation on java interop says the following: The preferred idiomatic forms for accessing field or method members are given above.

clojure and scala interop

最后都变了- 提交于 2019-12-23 06:56:41
问题 I am familiar that scala classes / objects can be called from clojure, as scala compiles to bytecode, and clojure is comfortable with it. However is it as painless calling clojure functions, and importing namespaces from scala ? I would like to mix the excellent lift framework and clojure, basically call clojure code from lift. 回答1: Semantics for imports in Scala are basically the same as Java. You should be able to get the info you need by reading up on how to invoke Clojure code from Java,

Simplest way to ensure var is vector

[亡魂溺海] 提交于 2019-12-23 05:15:16
问题 What is the "simplest"/shortest way to ensure a var is a vector? Self-written it could look like (defn ensure-vector [x] (if (vector? x) x (vector x)) (ensure-vector {:foo "bar"}) ;=> [{:foo "bar"}] But I wonder if there is already a core function that does this? Many of them ( seq , vec , vector , list ) either fail on maps or always apply. I also wonder what would be the best name for this function. box , singleton , unit , v , cast-vector , to-vector , ->vector , !vector , vector! , vec! ?

Deploying to heroku with clojure project, production environment issues

戏子无情 提交于 2019-12-23 05:08:59
问题 I have a picture gallery application I made from the "Web Development with Clojure" book and I am at the point of deploying it to Heroku. I have tried making it work as both a standalone uberjar and with trampoline. I tried to use environ in the beginning, but kept getting database value errors on "db-spec" so I stopped using it to make it run fine locally. I tried to set my own environment variables, and also to use a main.clj file. I edited my profile settings info and can get it to deploy