clojure

Alternatives to java on android

雨燕双飞 提交于 2019-12-20 18:31:07
问题 I just got myself an android phone and I'm dying to start coding on it ! However I'm not a big java fan, although I can live with that, I would like to know if there're reasonable alternatives for the android virtual machine. I've done a medium sized project using clojure, however from the reviews I read, it's very slow when running on android. How about scala ? I read that some people did experiments with it in android, is it "fast enough" ? How big is the learning curve ? Cheers, Ze Maria

What programming language features are well suited for developing a live coding framework?

[亡魂溺海] 提交于 2019-12-20 18:26:13
问题 I would like to build a "live coding framework". I should explain what is meant by "live coding framework". I'll do so by comparing live coding to traditional coding. Generally put, in traditional programming you write code, sometimes compile it, then launch an executable or open a script in some sort of interpreter. If you want to modify your application you must repeat this process. A live coding framework enables code to be updated while the application is running and reloaded on demand.

Dynamic method calls in a Clojure macro?

好久不见. 提交于 2019-12-20 18:01:15
问题 I'm attempting to write a macro which will call java setter methods based on the arguments given to it. So, for example: (my-macro login-as-fred {"Username" "fred" "Password" "wilma"}) might expand to something like the following: (doto (new MyClass) (.setUsername "fred") (.setPassword "wilma")) How would you recommend tackling this? Specifically, I'm having trouble working out the best way to construct the setter method name and have it interpreted it as a symbol by the macro. 回答1: The nice

Anonymous function returning 1 using #()

大兔子大兔子 提交于 2019-12-20 17:37:34
问题 Using defn or fn it's easy to create a function that taking one argument that ignores it and returns 1: (defn ret1 [arg] 1) (fn [arg] 1) Is it possible to do this with the #() macro? I don't mean using something ugly or "cheating" like #(/ % %) or #(if (nil? %) 1 1) I mean literally ignoring the parameter and returning 1. I can't find a clean syntax that works. 回答1: #(do %& 1) ... but (constantly 1) is better. 回答2: The #() syntax can't be used to create functions that have unused parameters

shutdown hook doesn't fire when running with “lein run”

。_饼干妹妹 提交于 2019-12-20 17:34:30
问题 I have the following code: (ns test-hook.core) (defn -main [] (.addShutdownHook (Runtime/getRuntime) (Thread. #(println "shutdown"))) (println "start") (doseq [i (range 1 6)] (Thread/sleep 1000) (println i))) and the following project.clj (defproject test-hook "1.0.0-SNAPSHOT" :aot :all :main test-hook.core :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.2.0"]]) when I run it with "lein run" the shutdown hook only gets executed on normal program execution, not

Help me write a Clojure macro which automatically adds metadata to a function definition

天涯浪子 提交于 2019-12-20 17:29:56
问题 I realize that the first rule of Macro Club is Don't Use Macros, so the following question is intended more as an exercise in learning Clojure than anything else (I realize this isn't necessarily the best use of macros). I want to write a simple macro which acts as a wrapper around a regular (defn) macro and winds up adding some metadata to the defined function. So I'd like to have something like this: (defn-plus f [x] (inc x)) ...expand out to something like this: (defn #^{:special-metadata

Pretty print in Clojure

浪尽此生 提交于 2019-12-20 17:29:30
问题 Is there a pretty printing function in Clojure that would output data-structures like lists and structs in a human-readable way? 回答1: clojure-contrib now has a pprint function. The API documentation is at http://richhickey.github.com/clojure-contrib/pprint-api.html 回答2: As Chouser has mentioned, in 1.3 pprint is moved into clojure itself. http://clojure.github.io/clojure/clojure.pprint-api.html#clojure.pprint/pprint You can (:require clojure.pprint) and start using it. 回答3: A pretty printer

Pretty print in Clojure

不问归期 提交于 2019-12-20 17:29:27
问题 Is there a pretty printing function in Clojure that would output data-structures like lists and structs in a human-readable way? 回答1: clojure-contrib now has a pprint function. The API documentation is at http://richhickey.github.com/clojure-contrib/pprint-api.html 回答2: As Chouser has mentioned, in 1.3 pprint is moved into clojure itself. http://clojure.github.io/clojure/clojure.pprint-api.html#clojure.pprint/pprint You can (:require clojure.pprint) and start using it. 回答3: A pretty printer

Emacs htmlize in batch mode?

江枫思渺然 提交于 2019-12-20 15:25:35
问题 I like to use htmlize-file in emacs to turn clojure source files into html. I want to use it from the linux command line instead, or programmatically from clojure itself. I tried $ emacs --eval "(htmlize-file \"/home/john/file.clj\" ) (kill-emacs)" and $ emacs -batch --eval "(htmlize-file \"/home/john/file.clj\" )" Both work, with caveats. The first opens an X-window, which seems a bit inelegant, but it does do exactly the same highlighting that I'd see in a buffer, which is what I want. The

Implementing a cron type scheduler in clojure

旧城冷巷雨未停 提交于 2019-12-20 14:23:20
问题 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)) ;