clojure

Clojure macro: Create local vars from a map [duplicate]

安稳与你 提交于 2019-12-20 04:25:26
问题 This question already has answers here : In Clojure, how to destructure all the keys of a map? (3 answers) Closed 10 months ago . I have this sample code where I create vars by iterating over the key value pair of the map. (defmacro block [bindings & body] `(let [ ~@(mapcat (fn [[k v]] [(if (symbol? k) k (symbol (name k))) `~v]) bindings) ] ~body)) (block {:a 1 :b 2} (if true (prn "true" a b) (prn "false"))) It works fine. Ouput: "true" 1 2 But now I want to pass the same map as a var but, it

How to get an Fn which calls a Java method?

六月ゝ 毕业季﹏ 提交于 2019-12-20 02:37:46
问题 I'm learning Clojure. I wrote this code to recursively walk a directory. (tree-seq #(.isDirectory %1) #(.listFiles %1) (File. "/my-directory")) Why can't I use .isDirectory as a first-class function in Clojure? Is there a better way to rewrite this code? 回答1: Java methods aren't clojure functions because you can't call a method on its own; you have to call a method on an object, and it has to be an object of the type that the method expects. In other words, in java, a method cannot be fully

Pygments syntax highlighting in Jekyll without starting a <div>

血红的双手。 提交于 2019-12-20 02:37:24
问题 If you use Jekyll with the Pygments syntax-highlighting package, it’s possible to write {% highlight clojure %} (def something :foobar) {% endhighlight %} which produces a <div> containing that line, syntax-highlighted according to Clojure syntax. But is there a way to get the syntax highlighting in the middle of a paragraph? I’d like to be able to write In Clojure, keywords like {% highlight clojure %}:foobar{% endhighlight %} are prepended by colons. The desired behavior here is that the

how to return only truthy values as the result of a map operation

倖福魔咒の 提交于 2019-12-20 02:15:51
问题 I have a function below to return the vowels. However I would like to only return truthy values, how do I do that ? (map #{\a \e \i \o \u} (seq (char-array "Hello"))) => (nil \e nil nil \o) 回答1: filter identity (map f ... = (keep f ... . > (keep #{\a \e \i \o \u} (seq (char-array "Hello"))) (\e \o) 回答2: I guess this is the same as counting only truthy values in a collection, so use the identity function with filter: (filter identity (map #{\a \e \i \o \u} (seq (char-array "Hello"))) 回答3:

Clojure core.logic CLP(FD) projecting FD variables

拜拜、爱过 提交于 2019-12-20 01:59:20
问题 I'm working on a naive square-packing algorithm using Clojure's core.logic CLP(FD) library (core.logic version 0.8.3). Squares are represented like so: [[[x11 y11] [x12 y12]] [[x21 y21] [x22 y22] ...]] with each square represented as the coordinates of its top-left and bottom-right corners. Coordinates are FD variables, within a certain interval. I want to define the size of a solution as the distance between the top-right corner and bottom-right corners of the closest and farthest squares to

再识redis篇_list类型

旧巷老猫 提交于 2019-12-20 00:18:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 以有序的方式储存多个可重复的值 推入和弹出操作 了解如何向列表添加项,以及如何从列表里面删除项。 从列表的左端推入 值 LPUSH key value [value ...] 将一个或以上数量的值依次推入到列表的左端,命令返回新 值被推入之后,列表目前包含的 项数量。 复杂度为 O(N) ,其中 N 为被推入值的数量,如果只推入一个值,那么命令的复杂度为 O(1) 。 redis> LPUSH lst "Lua" (integer) 1 redis> LPUSH lst "Python" (integer) 2 redis> LPUSH lst "C" (integer) 3 如图 举个例子,执行命令: redis> LPUSH lst "Lua" "Python" "C" (integer) 3 和依次执行以下三个命令的效果一样: LPUSH lst "Lua" LPUSH lst "Python" LPUSH lst "C" RPUSH key value [value ...] 将一个或以上数量的值依次推入到列表的右端,命令返回新 值被推入之后,列表目前包含的 项数量。 复杂度为 O(N) ,其中 N 为被推入值的数量,如果只推入一个值,那么命令的复杂度为 O(1) 。 redis> RPUSH lst

IntelliJ IDEA plugin development in other JVM languages

夙愿已清 提交于 2019-12-19 19:58:31
问题 Is it possible to use other JVM languages such as Scala and Clojure for developing an IntelliJ IDEA plugin? Or do we have to use Java for this purpose? I could find no pointers on this on web, hence posting the question here. 回答1: Yes, it is entirely possible. Any plugin essentially is a set of extensions for several extension points which IDEA API provides. These extensions are regular java classes implementing predefined interfaces, and these classes are referenced to in the manifest. Also,

Leiningen compilation order?

江枫思渺然 提交于 2019-12-19 19:14:43
问题 I'm just learning how to lein , and I'd like to use from a Java source a class created by deftype in a Clojure source. This wasn't covered in the basic tutorial and I can't get it to work properly. The problem is that Java source can't import Clojure class, since it hasn't been compiled yet. And Clojure class isn't compiled, since compilation is aborted by the Java source. I give a minimal example: Create a new project with: lein new app javafoo Add to project.clj :aot :all :java-source-paths

Good Web Server/Servlet Container for Clojure Web Apps?

99封情书 提交于 2019-12-19 18:58:35
问题 I am looking for a good production web server/servlet container for my compojure web appliction. What are the pros and cons of using Jetty or Tomcat or other server for a Clojure web app using compojure? Is there any good documentation for using a web server with Clojure for production, or tools? I would prefer a web server that is flexible, easy to configure and has good documentation on how to configure and use it. 回答1: I think there is not yet a pure Clojure Webserver, but I heard that

Good Web Server/Servlet Container for Clojure Web Apps?

爷,独闯天下 提交于 2019-12-19 18:57:14
问题 I am looking for a good production web server/servlet container for my compojure web appliction. What are the pros and cons of using Jetty or Tomcat or other server for a Clojure web app using compojure? Is there any good documentation for using a web server with Clojure for production, or tools? I would prefer a web server that is flexible, easy to configure and has good documentation on how to configure and use it. 回答1: I think there is not yet a pure Clojure Webserver, but I heard that