clojure

Using “maybe ARefs” in higher-order functions

…衆ロ難τιáo~ 提交于 2019-12-22 19:59:25
问题 I want to know how to wrap a function (or function definition) such that it becomes seemingly agnostic to whether the parameters passed to it are mutable or immutable -- but if any parameter it is given is mutable, it should dereference that parameter every time it is called, to get the current value. I could write a function that requires each parameter to be mutable storage that it then dereferences each time it is called. But there's a performance hit (very, very small, I know!) to

Clojurescript Array-Map order

末鹿安然 提交于 2019-12-22 14:52:54
问题 How can I keep order in array-map? Array-map with a length above 8 behaves completely different in Clojure and Clojurescript. Example: cljs (array-map :a true :c true :d false :b true :z false :h false :o true :p true :w false :r true :t false :g false) -> {:o true, :p true, :r true, :t false, :w false, :z false, :a true, :b true, :c true, :d false, :g false, :h false} clj (array-map :a true :c true :d false :b true :z false :h false :o true :p true :w false :r true :t false :g false) -> {:a

Clojurescript Array-Map order

99封情书 提交于 2019-12-22 14:52:19
问题 How can I keep order in array-map? Array-map with a length above 8 behaves completely different in Clojure and Clojurescript. Example: cljs (array-map :a true :c true :d false :b true :z false :h false :o true :p true :w false :r true :t false :g false) -> {:o true, :p true, :r true, :t false, :w false, :z false, :a true, :b true, :c true, :d false, :g false, :h false} clj (array-map :a true :c true :d false :b true :z false :h false :o true :p true :w false :r true :t false :g false) -> {:a

How to add new JVM languages e.g. Scala, Clojure, Fantom, Groovy to Eclipse IDE?

徘徊边缘 提交于 2019-12-22 13:58:08
问题 What's a prefereed way to download Scala , via scala-lang.org, can it be added directly by the Eclipse IDE or how to add Scala to Eclipse IDE? Is there a convention on how to add a JVM language? Update I could add Clojure and Scala from Help...install new software so now I can create those kinds of projects: 回答1: You typically install a plugin for that language using Eclipse's build in plugin language. for instance for Clojure you can search the plugin manager for "counter clockwise" to get

map not quite lazy?

守給你的承諾、 提交于 2019-12-22 12:26:34
问题 map doesn't seem quite as lazy as I would like, in this example map calls the function one time as I would expect: (first (map #(do (println "x: " %) %) '(0 1))) but in these two examples it calls the function two times: (first (map #(do (println "x: " %) %) '[0 1])) (first (map #(do (println "x: " %) %) (doall (range 2)))) What is the underlying principle for making the choice to be lazy or not? Is there a way to guarantee total laziness? Thanks for your time. 回答1: Map (and similar HOFs that

Dynamically loading an aliased namespace to another Clojure namespace

冷暖自知 提交于 2019-12-22 11:05:52
问题 I am trying to load a namespace from a file during runtime. For this namespace I would like to have a common alias, so I can access functions from that namespace with a unified, qualified name independent from the actual namespace of the loaded file. Example (not working): ;; bar_a.clj (ns bar-a) (defn hello-world [] "hello world a") ;; bar_b.clj (ns bar-b) (defn hello-world [] "hello world b") ;; foo.clj (ns foo) (defn init [ns-name] (let [ns-symbol (symbol ns-name)] (require `[ns-symbol :as

Clojure way of reading large files and transforming data therein

為{幸葍}努か 提交于 2019-12-22 10:56:19
问题 I am processing a Subrip subtitles file which is quite large and need to process it one subtitle at a time. In Java, to extract the subtitles from file, I would write a method with following signature: Iterator<Subtitle> fromSubrip(final Iterator<String> lines); The use of Iterator gives me two benefits: The file is never in the memory in its entirety, nor is any of its transformed stage. An abstraction wherein I can loop over a collection of Subtitle objects without the memory overhead.

Canonical Way to Ensure Only One Instance of a Service Is Running / Starting / Stopping in Clojure?

点点圈 提交于 2019-12-22 10:53:06
问题 I'm writing a stateful server in Clojure backed by Neo4j that can serve socket requests, like HTTP. Which means, of course, that I need to be able to start and stop socket servers from within this server. Design-wise, I would want to be able to declare a "service" within this server and start and stop it. What I'm trying to wrap my mind around in Clojure is how to ensure that starting and stopping these services is thread-safe. This server I'm writing will have NREPL embedded inside it and

Holding onto the head of sequence when using “rest”

柔情痞子 提交于 2019-12-22 10:37:06
问题 I am parsing a big csv file and I am using the first line of it as the keys for the records. So for a csv file like: header1,header2 foo,bar zoo,zip I end up with a lazy seq like: ({:header1 "foo" :header2 "bar"}, {:header1 "zoo" :header2 "zip"}) The code working fine, but I am not sure if in the following function I am holding the head of "lines" or not. (defn csv-as-seq [file] (let [rdr (clojure.java.io/reader file)] (let [lines (line-seq rdr) headers (parse-headers (first lines))] (map

Compojure: access filesystem

丶灬走出姿态 提交于 2019-12-22 10:30:03
问题 this is my project.clj file: (defproject org.github.pistacchio.deviantchecker "0.9.0" :description "A one page application for keeping track of changes on deviantart.com gallieries" :dependencies [[org.clojure/clojure "1.2.1"] [org.clojure/clojure-contrib "1.2.0"] [enlive "1.0.0"] [compojure "0.6.4"] [ring/ring-jetty-adapter "1.0.0-beta2"]] :dev-dependencies [[lein-ring "0.4.6"]] :ring {:handler org.github.pistacchio.deviantchecker.core/app} :main org.github.pistacchio.deviantchecker.core)