clojure

Is there a standalone Clojure package within Leiningen?

牧云@^-^@ 提交于 2019-12-22 06:02:06
问题 After installing leiningen with this script https://raw.github.com/technomancy/leiningen/preview/bin/lein , I can use the repl by typing lein repl , so I think the clojure has already been installed by leiningen . Do I need to download the JAR of the clojure again from the offical site? If there's no need to do this, where's the JAR file of clojure that leiningten depends on? 回答1: What I've found with lein is installing it and then depending on a specific version of Clojure causes that

Is there a standalone Clojure package within Leiningen?

╄→гoц情女王★ 提交于 2019-12-22 06:01:12
问题 After installing leiningen with this script https://raw.github.com/technomancy/leiningen/preview/bin/lein , I can use the repl by typing lein repl , so I think the clojure has already been installed by leiningen . Do I need to download the JAR of the clojure again from the offical site? If there's no need to do this, where's the JAR file of clojure that leiningten depends on? 回答1: What I've found with lein is installing it and then depending on a specific version of Clojure causes that

Get available clojure namespaces

早过忘川 提交于 2019-12-22 05:27:30
问题 Is there an idiomatic way to get available namespaces that can be used? (all-ns) returns only already used namespaces. (Package/getPackages) returns all Java packages available for import , but only those Clojure namespaces that are already used. Then I stumbled upon this post, but it uses some classpath magic. So I want to get something like ('clojure.core 'clojure.set ... 'clojure.contrib.accumulators 'clojure.contrib.condition ...) if I have the clojure.jar and contrib.jar on my classpath,

Use a clojure macro to automatically create getters and setters inside a reify call

淺唱寂寞╮ 提交于 2019-12-22 05:27:10
问题 I am trying to implement a huge Java interface with numerous (~50) getter and setter methods (some with irregular names). I thought it would be nice to use a macro to reduce the amount of code. So instead of (def data (atom {:x nil})) (reify HugeInterface (getX [this] (:x @data)) (setX [this v] (swap! data assoc :x v))) I want to be able to write (def data (atom {:x nil})) (reify HugeInterface (set-and-get getX setX :x)) Is this set-and-get macro (or something similar) possible? I haven't

how to transform a seq into a tree

拜拜、爱过 提交于 2019-12-22 05:25:30
问题 I have a seq of maps such as the coll below. I want to arrange it in a tree. Each map has a key named :parent which is the :id of the parent. Any hints on how can I do it ? (def coll [{:id 1} {:id 2 :parent 1} {:id 3 :parent 1} {:id 4 :parent 2} {:id 5 :parent 4} {:id 6 :parent 5} {:id 7 :parent 5} {:id 8 :parent 5} {:id 9 :parent 7}]) 回答1: If it walks like a tree... (require '[clojure.zip :as z]) (defn create-zipper [s] (let [g (group-by :parent s)] (z/zipper g #(map :id (g %)) nil (-> nil g

Parse string into a tree structure?

假装没事ソ 提交于 2019-12-22 05:22:03
问题 I'm trying to figure out how to parse a string in this format into a tree like data structure of arbitrary depth. "{{Hello big|Hi|Hey} {world|earth}|{Goodbye|farewell} {planet|rock|globe{.|!}}}" [[["Hello big" "Hi" "Hey"] ["world" "earth"]] [["Goodbye" "farewell"] ["planet" "rock" "globe" ["." "!"]]]] I've tried playing with some regular expressions for this (such as #"{([^{}]*)}" ), but everything I've tried seems to "flatten" the tree into a big list of lists. I could be approaching this

Parse string into a tree structure?

て烟熏妆下的殇ゞ 提交于 2019-12-22 05:21:08
问题 I'm trying to figure out how to parse a string in this format into a tree like data structure of arbitrary depth. "{{Hello big|Hi|Hey} {world|earth}|{Goodbye|farewell} {planet|rock|globe{.|!}}}" [[["Hello big" "Hi" "Hey"] ["world" "earth"]] [["Goodbye" "farewell"] ["planet" "rock" "globe" ["." "!"]]]] I've tried playing with some regular expressions for this (such as #"{([^{}]*)}" ), but everything I've tried seems to "flatten" the tree into a big list of lists. I could be approaching this

Is there a html-only templates system for php?

元气小坏坏 提交于 2019-12-22 05:18:21
问题 I have started coding in clojure, and I'm really impressed by Enlive. One thing that I really like about it is that Enlive uses html-only templates. So a template is a file with html in it, ending in .html, simple as that. It gets parsed into a dom tree and then that dom tree is manipulated by clojure/enlive, combined, made dynamic, etc. No syntax in the html template files, a beautifully clean separation. Another example of a similar system, done via javascript, is PURE. Is there anything

Using 'map' with different sized collections in clojure

落花浮王杯 提交于 2019-12-22 05:01:01
问题 I'd like to understand the idiomatic way with which to operate over collections of different sizes in clojure. Is there a way I can tell the function 'map' to pad the rest of a collection with some default value? As an example, suppose I have 3 vectors: (def x [1 2 3 4]) (def y [1 2 3 4 5]) (def z [1 2 3 4 5 6 7]) (map + x y z) ; yields (3 6 9 12) In this case, how can I pad x and y with zeroes and have this yield: (3 6 9 12 10 6 7) 回答1: map doesn't do it itself, but you can use a combination

Clojure deftype calling function in the same namespace throws “java.lang.IllegalStateException: Attempting to call unbound fn:”

南笙酒味 提交于 2019-12-22 04:55:15
问题 I'm placing Clojure into an existing Java project which heavily uses Jersey and Annotations. I'd like to be able to leverage the existing custom annotations, filters, etc of the previous work. So far I've been roughly using the deftype approach with javax.ws.rs annotations found in Chapter 9 of Clojure Programming. (ns my.namespace.TestResource (:use [clojure.data.json :only (json-str)]) (:import [javax.ws.rs DefaultValue QueryParam Path Produces GET] [javax.ws.rs.core Response])) ;;My