clojure

Implementing a cron type scheduler in clojure

丶灬走出姿态 提交于 2019-12-20 14:23:01
问题 I'm looking for any way for clojure that can trigger an event at a given time, For example: I want a particular process to start at 9:30am and then I can trigger another process to start running half an hour later etc. Thanks in advance! Updated 2: Thanks @arthur-ulfeoldt and @unknown-person who also suggested using https://github.com/samaaron/at-at before deleting his answer. The documentation is a little out of date but here's how I got going. (use 'overtone.at-at) (def my-pool (mk-pool)) ;

How to clear the REPL in cider-mode?

跟風遠走 提交于 2019-12-20 12:39:07
问题 I am not meaning cleaning up the text output of REPL; I mean cleaning up all evaluated results in REPL. During developing, repeatedly C-c C-q and C-c M-j is low efficiency. UPDATE There may be some bad debug behaviour of mine. I am not sure how other people develop progs with CIDER, but I really need the functionality mentioned above. I guess other developers also encounter same problems as mine. For example, at the top of a clojure prog unit, I use declare to declare a function foo , which

Idiomatic way to write Clojure code for repeatedly reading lines from the console?

徘徊边缘 提交于 2019-12-20 12:34:27
问题 Recently I was writing a little CLI script which needed to repeatedly read dates from the console (the number of dates to read was calculated and could be different each time). Sample Ruby code to give you the idea: dates = x.times.collect { print "Enter date: "; Date.parse(gets.chomp) } Just for the heck of it, I wrote the script in Clojure, and wound up using some rather ugly code with swap! and loop...recur . I'm wondering what the cleanest way to achieve the desired effect in Clojure

nrepl.el: how to eval clojure buffer form to nrepl buffer instead of echo area?

你离开我真会死。 提交于 2019-12-20 12:23:03
问题 I'm using nrepl.el from git (0.1.6-preview, via el-get recipe), and I would like clojure buffer evals: C-x C-e, C-M-x, C-c C-r for form, top-level form and region respectively, to send themselves to the nrepl buffer and evaluate there, rather than the default behavior of evaluating off-screen with results returned to the echo area. Is there any way to do this, or is there another set of keybindings for this purpose that I'm not recognizing by their descriptions? Thanks. 回答1: The behavior you

How to implement lambda as a function called “lambda” in Clojure?

走远了吗. 提交于 2019-12-20 11:53:02
问题 I'd like to be able to define lambdas using common Lisp syntax, in Clojure. For example: (lambda (myarg) (some-functions-that-refer-to myarg)) This needs to result in the same as: #(some-functions-that-refer-to %) In my case, I know I'll always have exactly one arg, so perhaps that simplifies things. (But it can be called anything -- "myarg" or whatever.) I suspect a workable solution is to "(defmacro lambda ...". If so, I'm not sure of the best way to proceed. How to cleanly translate the

Clojure namespace management - Is there a way to save and restore the state of clojure repl namespaces, imports etc.?

泄露秘密 提交于 2019-12-20 10:39:40
问题 Clojure has a large number functions/macros for working with namespaces and java package imports. To my (limited) understanding the set up of namespaces can be considered state in a clojure process (repl). When working iteratively at a REPL session, especially when source files are (re)-loaded, I can find it easy to get confused - often when I make a mistake or syntax error in namespace configuration. Other times I want to try out refactoring namespaces/aliases/reference filters but can't

Clojure namespace management - Is there a way to save and restore the state of clojure repl namespaces, imports etc.?

笑着哭i 提交于 2019-12-20 10:39:13
问题 Clojure has a large number functions/macros for working with namespaces and java package imports. To my (limited) understanding the set up of namespaces can be considered state in a clojure process (repl). When working iteratively at a REPL session, especially when source files are (re)-loaded, I can find it easy to get confused - often when I make a mistake or syntax error in namespace configuration. Other times I want to try out refactoring namespaces/aliases/reference filters but can't

How can one create cyclic (and immutable) data structures in Clojure without extra indirection?

人盡茶涼 提交于 2019-12-20 10:28:18
问题 I need to represent directed graphs in Clojure. I'd like to represent each node in the graph as an object (probably a record) that includes a field called :edges that is a collection of the nodes that are directly reachable from the current node. Hopefully it goes without saying, but I would like these graphs to be immutable. I can construct directed acyclic graphs with this approach as long as I do a topological sort and build each graph "from the leaves up". This approach doesn't work for

What does the 'swank-clojure' do exactly, and do we have 'swank-SOMETHING_ELSE'?

妖精的绣舞 提交于 2019-12-20 09:56:26
问题 My superficial understanding is that 'swank-clojure' makes 'M-x slime-connect' possible. I mean, it gives a connection to a clojure server something like 'lein swank'. Is my understanding correct? If not, what's the purpose of swank? Then, is there any 'swank-SOMETHING_ELSE' for other lisp like implementations? For example, swank-clisp? Do I need 'swank-clojure' for using SLIME/Clojure with 'M-x slime'? ADDED I found this link pretty useful. 回答1: SLIME and swank form a client server

Lazy infinite sequences in Clojure and Python

大城市里の小女人 提交于 2019-12-20 09:37:52
问题 Here are the best implementations I could find for lazy infinite sequences of Fibonacci numbers in both Clojure and Python: Clojure: (def fib-seq (lazy-cat [0 1] (map + fib-seq (rest fib-seq)))) sample usage: (take 5 fib-seq) Python: def fib(): a = b = 1 while True: yield a a,b = b,a+b sample usage: for i in fib(): if i > 100: break else: print i Obviously the Python code is much more intuitive. My question is: Is there a better (more intuitive and simple) implementation in Clojure ? Edit I'm