第一个clojure 的hello world程序
来源:互联网 发布:中信银行淘宝卡 编辑:程序博客网 时间:2024/04/30 04:45
clojure是一种可以在java虚拟机上运行的函数式编程语言。storm就是用clojure和java编写的。
环境:
ubuntu 12.04
1.apt-get install lein
安装lein,leinigen是clojure的项目管理工具,类似于maven是java的项目管理工具一样。
2.apt-get install clojure
安装clojure的运行环境
3.lein new hello
创建一个hello的clojure项目
4.修改代码:
hello/src/hello.core
(ns hello.core)
(defn -main
[& args]
(println “Hello, World!”))
修改project.clj
增加
:main hello.core
指定main函数
lein run
或者
lein run hello.core
显示
Hello, World!
5.也可以通过repl的方式执行
lein repl
user=> (require ‘hello.core)
nil
user=> (hello.core/-main)
Hello, World!
nil
6.也可以不依赖lein,直接用clojure执行。
编写PigLatin.clj
; This is Clojure code.
; When a set is used as a function, it returns a boolean
; that indicates whether the argument is in the set.
(def vowel? (set “aeiou”))
(defn pig-latin [word] ; defines a function
; word is expected to be a string
; which can be treated like a sequence of characters.
(let [first-letter (first word)] ; assigns a local binding
(if (vowel? first-letter)
(str word “ay”) ; then part of if
(str (subs word 1) first-letter “ay”)))) ; else part of if
(println (pig-latin “red”))
(println (pig-latin “orange”))
执行clojure PigLatin.clj
返回
edray
orangeay
7.要使vim能够彩色地显示clojure代码,按下面的教程安装相关的插件就可以了。
https://github.com/daveray/vimclojure-easy
- 第一个clojure 的hello world程序
- silverlight的第一个程序hello world.
- java的第一个程序 ----Hello World
- C++的第一个程序:Hello World
- Hello World -- 我的第一个程序
- nodejs的第一个程序Hello World
- Springboot的第一个Hello World程序
- Springboot的第一个Hello World程序
- Python 的第一个 hello world 程序!
- 第一个“Hello World”程序
- 第一个程序:"Hello World"
- 第一个程序:Hello World
- 第一个程序:Hello World
- Hello World 第一个程序
- 第一个程序“Hello World !”
- MFC的第一个程序Hello World, Hello MFC
- Linux下的第一个程序Hello World
- 用VC写的第一个窗口程序 Hello World!
- dubbo服务治理
- JOOQ初学-简单的增删改查demo
- DownLoadUtil
- IDEA+jetty配置jndi数据源
- 随手写了一段C++访问LDAP, 并且获取sid的代码
- 第一个clojure 的hello world程序
- STL - map学习总结
- linux grep命令
- 下拉抽屉菜单的实现
- hdu 2825 Wireless Password (ac自动机+状态压缩dp)
- BaseAdapter里面处理单击事件
- SQL Server 删除作业Job (亲自实践)
- ubuntu12.04下安装与配置tomcat6
- [BZOJ 1001] 狼抓兔子