欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

clojure 初试

程序员文章站 2022-07-14 14:44:48
...

Twitter开源的著名的分布式并行计算框架Storm就是用Clojure编写的。
http server 例子:https://github.com/moonranger/clj.tr069

Datomic
http://jerrypeng.me/2015/05/26/talk-about-monitoring-again/

Leiningen for project automation package management and dependencies and is configured using Clojure syntax.
Maven integration

readers for: maps, sets, vectors, lists.
Lisp-1
macro: qualify symbols with namespace.
concurrent: software transactional memory, reactive system, channel-based

clojure download

clojure国内镜像下载

http://maven.ibiblio.org/maven2/org/clojure/clojure/1.9.0-alpha9/
http://maven.aliyun.com/nexus/content/groups/public/org/clojure/clojure

leiningen下载:

在~/.lein 目录下:

https://github.com/technomancy/leiningen/tree/master/bin/lein.bat 放到bin/

https://github.com/technomancy/leiningen/releases/download/2.7.1/leiningen-2.7.1-standalone.zip 重命名为
/self-installs/leiningen-2.7.1-standalone.jar

clojure repl

java -cp ~/tmp/clojure-1.9.0-alpha9.jar clojure.main

(println (str "Hello, " \u4e16)) ; to the console
(javax.swing.JOptionPane/showMessageDialog nil (str "Hello, " \u4e16 "!")) ; using Java GUI

leiningen repl

usage

lein new hello
cd hello
lein run -m hello.core/foo 123
> 123 Hello, World!

lein deps
lein test

project.clj 中加入 :main xx <==> -m xx

lein repl
> (require 'hello.core)
> (hello.core/foo 123)

lein trampoline run -m hello.core/foo 5000 ;省内存

emacs clojure repl

init.el
(defvar my-packages '(better-defaults
                      projectile
                      clojure-mode
                      cider))

(dolist (p my-packages)
  (unless (package-installed-p p)
    (package-install p)))

~/.lein/profiles.clj
 {:user {:plugins [[cider/cider-nrepl "0.8.1"]]}}

;;;M-x eval-buffer
;;;M-x package-list-packages
;;;start repl: M-x cider-jack-in
;;;toggle menu: M-x menu-bar-mode

分发给终端用户使用

(defproject my-stuff ... :main my.stuff)
src/my/stuff.clj
(ns my.stuff (:gen-class))
(defn -main [& args]
 (println "your args:" args))

lein uberjar
java -jar my-stuff-standalone.jar are you ok

在线修改服务器

不重启开发服务器的情况下重载源文件 [3]

project.clj
:plugins [[lein-ring "0.8.7"]]
:ring {:handler your-app.core/handler}

lein deps
lein ring server

todo

compojure-clojure
http://blog.csdn.net/lrq1988/article/details/12155119

destruct
http://blog.csdn.net/lrq1988/article/details/14120401

ref

[1] http://wiki.fnil.net/index.php?title=Leiningen%E6%95%99%E7%A8%8B%E4%B8%AD%E6%96%87%E7%89%88

[2] (http://wiki.fnil.net/index.php?title=Clojure%E5%B9%B6%E5%8F%91)

[3] https://github.com/ring-clojure/ring/wiki

[4] 速成教程 http://blog.csdn.net/ithomer/article/details/16807461
http://java.ociweb.com/mark/clojure/article.html#Macros

相关标签: clojure