clojure

future not working with javax.mail

风流意气都作罢 提交于 2020-01-04 13:40:52
问题 I'm playing with future and and can't seem to get it to work with javax.mail . For example, for fun, I'm trying to set up a compojure handler to grab a bunch of emails and put them into a database, but deliver a response to the client before the emails have all been gathered and inserted. I have a few println s going on in the import-posts function (below), and when I run this from the repl, it works fine, printing 142 journal messages. the first time (because the db is empty), and No new

How can i use a session for both clojure/script

↘锁芯ラ 提交于 2020-01-04 13:10:53
问题 How can i use single session for both clojure and clojurescript. For my login web application Server side i am using clojure and client side clojurescript. And i need a session which is accessible from both client and server. Is that possible? 回答1: The example sente project has a session which is accessible from both client and server. You will probably need to spend some time with it and mould it to your needs. But the example itself shows logging in and then a :uid inside :session , which

Ways to start Clojure REPL?

女生的网名这么多〃 提交于 2020-01-04 06:29:17
问题 Name the ways you know to start the Clojure REPL. What is your favourite ? Does it highlight things for you ? I know of : 1. NetBeans IDE with the Enclojure plugin, and 2. the Leiningen shell script : lein repl No favorite for me so far, and I'd certainly like some colors. What else ? 回答1: Syntax-highlighted Clojure REPL is entirely possible in Emacs -- I wrote the necessary code in response to a very old question here on SO: Is there a colored REPL for Clojure? I have since tweaked it to

Reduce in Clojure

最后都变了- 提交于 2020-01-04 06:03:46
问题 Can someone please explain how the below anonymous function is evaluated? (defn min-by [f coll] (when (seq coll) (reduce (fn [min this] (if (> (f min) (f this)) this min)) coll))) (min-by :cost [{:cost 100} {:cost 36} {:cost 9}]) ;=> {:cost 9} I don't understand where the arguments min and this come from. It seems like coll is being implicitly destructured perhaps. How can I better understand what this function is doing? 回答1: Reduce expects a function as it's first argument. This function

How should I properly implement the core Clojure interfaces?

喜欢而已 提交于 2020-01-04 02:35:13
问题 If I'm implementing some data structure in Clojure using deftype , how should I decide which of the core Clojure interfaces to implement? I was unable to find a comprehensive guide to the various Clojure interfaces; in fact, the only relevant piece of information I was able to find was this question, which is very limited in scope. What I'm looking for is a list of each of the core Clojure interfaces, with a brief description of what it is and when you should implement it (or if you should

loading clojure-contrib

为君一笑 提交于 2020-01-04 02:34:34
问题 I'm new to the whole JVM thing, and trying to play with clojure. I'm attempting to load clojure-contrib and failing: # in bash $ java -cp /path/to/clojure.jar:/path/to/contrib.jar clojure.main # in REPL user=> (require 'clojure.contrib.math) nil user=> (sqrt 2) java.lang.Exception: Unable to resolve symbol: sqrt in this context (NO_SOURCE_FILE:10) Any pointers will be great - thanks. 回答1: I'm no expert, but it seemed like a namespace issue. The solution I employed was this: ;; for REPL user=>

What does non-relational mean in practice for core.logic?

孤街醉人 提交于 2020-01-03 20:57:04
问题 When trying to understand core.logic throgh the API docs I come across Non-Relational goals and relational goals. I have no idea what this means in practice and why it is important to annotate goals if they are relational or not. Can you explain with example how the goals are used differently depending on if they are relational or not? 回答1: In order to explain what non-relational means we need to revisit what relational means. If you consider pure functions in functional programming, they

Clojure: idiomatic update a map's value IF the key exists

醉酒当歌 提交于 2020-01-03 18:41:08
问题 Here's my problem: I want a function helpme that takes a map and replaces the keys :r and :g with empty vectors if and only if those keys exist. For example: Input: (helpme {:a "1" :r ["1" "2" "3"] :g ["4" "5"]}) Output: {:a "1" :r [] :g []} Input: (helpme {:a "1" :r ["1" "2" "3"]}) Output: {:a "1" :r []} I can define a function "helpme" that does this, but it's overly complicated, and I feel like there must be an easier (more idiomatic) way... Here's the overly complicated way I've done, as

Merging maps without overriding keys

徘徊边缘 提交于 2020-01-03 17:37:00
问题 I have a clojure function that returns a sequence of 1-key maps. I want to merge these maps into one map; however, if there are maps with the same key, I don't want to overwrite the values, only to combine them into a vector. merge seems to overwrite, and merge-with seems to seriously distort the type. I have: ({:foo "hello"} {:bar "world"} {:baz "!!!"} {:ball {:a "abc", :b "123"}} {:ball {:a "def", :b "456"}} {:ball {:a "ghi", :b "789"}}) I'd like: {:foo "hello" :bar "world" :baz "!!!" :ball

Merging maps without overriding keys

和自甴很熟 提交于 2020-01-03 17:36:51
问题 I have a clojure function that returns a sequence of 1-key maps. I want to merge these maps into one map; however, if there are maps with the same key, I don't want to overwrite the values, only to combine them into a vector. merge seems to overwrite, and merge-with seems to seriously distort the type. I have: ({:foo "hello"} {:bar "world"} {:baz "!!!"} {:ball {:a "abc", :b "123"}} {:ball {:a "def", :b "456"}} {:ball {:a "ghi", :b "789"}}) I'd like: {:foo "hello" :bar "world" :baz "!!!" :ball