clojure

Newbie transforming CSV files in Clojure

£可爱£侵袭症+ 提交于 2019-12-21 09:14:43
问题 I'm both new and old to programming -- mostly I just write a lot of small Perl scripts at work. Clojure came out just when I wanted to learn Lisp, so I'm trying to learn Clojure without knowing Java either. It's tough, but it's been fun so far. I've seen several examples of similar problems to mine, but nothing that quite maps to my problem space. Is there a canonical way to extract lists of values for each line of a CSV file in Clojure? Here's some actual working Perl code; comments included

Clojure case statement with classes

那年仲夏 提交于 2019-12-21 09:07:54
问题 I want to switch on the class of a given object in order to encode it. (defn encoded-msg-for [msg] (case (class msg) java.lang.Double (encode-double msg) java.lang.String (encode-str msg) java.lang.Long (encode-int msg) java.lang.Boolean (encode-bool msg) clojure.lang.PersistentArrayMap (encode-hash msg) clojure.lang.PersistentVector (encode-vec msg) nil "~" ) ) When I call (encoded-msg-for {}) , it returns No matching clause: class clojure.lang.PersistentArrayMap What is odd is that putting

How do I add my own JavaScript libs to ClojureScript?

雨燕双飞 提交于 2019-12-21 09:06:12
问题 I want to write a Google Chrome extension, using ClojureScript. With ClojureScript I can use all the Google Closure libs, but afaik access to the Chrome browser is not included in those libs. So I want to wrap all the Chrome stuff in my own JavaScript lib. So far I tried creating my own jar that has a single JavaScript file that just creates a Foo object and exports the constructor. I'v added this jar to the lib directory of the ClojureScript compiler (which also has for example goog.jar),

How to use a local repository for a Clojure library during initial development?

偶尔善良 提交于 2019-12-21 08:24:09
问题 I have a question about developing a Clojure library which is not answered in the suggested workflow for Library Development and Distribution as described here: http://clojure-doc.org/articles/ecosystem/libraries_authoring.html I am developing a library and want to test this in a clojure project. In this project I will have to add the library under development as a dependency. Is there an alternative for 'lein deploy clojars' which will deploy my library to a local repository? If so how would

How to use a local repository for a Clojure library during initial development?

僤鯓⒐⒋嵵緔 提交于 2019-12-21 08:24:05
问题 I have a question about developing a Clojure library which is not answered in the suggested workflow for Library Development and Distribution as described here: http://clojure-doc.org/articles/ecosystem/libraries_authoring.html I am developing a library and want to test this in a clojure project. In this project I will have to add the library under development as a dependency. Is there an alternative for 'lein deploy clojars' which will deploy my library to a local repository? If so how would

Will I be able to use Clojure functions as Lambdas in Java 8?

寵の児 提交于 2019-12-21 07:50:31
问题 I use a number of libraries in Clojure that produce higher order functions that conform to the "clojure.lang.IFn" interface. It has multiple arity overloads, I.e. the interface looks something like: public interface IFn extends Callable, Runnable{ public Object invoke() ; public Object invoke(Object arg1) ; public Object invoke(Object arg1, Object arg2) ; public Object invoke(Object arg1, Object arg2, Object arg3) ; .... etc. public Object applyTo(ISeq arglist) ; } Will I be able to use

Clojure: lazy magic

社会主义新天地 提交于 2019-12-21 07:36:06
问题 Almost 2 identical programs to generate infinite lazy seqs of randoms. The first doesn't crash. The second crash with OutOfMemoryError exception. Why? ;Return infinite lazy sequence of random numbers (defn inf-rand[] (lazy-seq (cons (rand) (inf-rand)))) ;Never returns. Burns the CPU but won't crash and lives forever. (last (inf-rand)) But the following crash pretty quickly: ;Return infinite lazy sequence of random numbers (defn inf-rand[] (lazy-seq (cons (rand) (inf-rand)))) (def r1 (inf-rand

clojure deferred function execution

怎甘沉沦 提交于 2019-12-21 07:32:08
问题 Ok Here is what i am trying to do (defn addresses [person-id] ;addresses-retrival ) (defn person [id] (merge {:addresses (addresses id)} {:name "john"})) In the above person function i want addresses to be retrieved only on demand , like only when i do (:addresses (person 10)) and not when (person 10) I am not sure if i am going about this right, being new to clojure. 回答1: You can use delay. (defn person [id] (delay {:addresses (addresses id) :name "john"})) (person 2) will then return a

clojure deferred function execution

微笑、不失礼 提交于 2019-12-21 07:31:32
问题 Ok Here is what i am trying to do (defn addresses [person-id] ;addresses-retrival ) (defn person [id] (merge {:addresses (addresses id)} {:name "john"})) In the above person function i want addresses to be retrieved only on demand , like only when i do (:addresses (person 10)) and not when (person 10) I am not sure if i am going about this right, being new to clojure. 回答1: You can use delay. (defn person [id] (delay {:addresses (addresses id) :name "john"})) (person 2) will then return a

Why no destructing in def form?

时光怂恿深爱的人放手 提交于 2019-12-21 07:25:55
问题 In a let form (Clojure here) I can doing something like (let [[u s v] (svd A)] (do-something-with u v)) where svd returns a list of length three. This is a very natural sort of thing to do, so why isn't that we don't we have (def [u s v] (svd A)) and its various generalizations as the default behavior of the def form? I don't see how this would interfere with anything that def is already doing. Can someone who understands the Zen of Lisp or Clojure explain why def does not support binding