-
Notifications
You must be signed in to change notification settings - Fork 1
Clojure 1
Minsun Lee edited this page Jul 22, 2014
·
4 revisions
public class StringUtils {
public static boolean isBlank(String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i ++) {
if ((Character.isWhitepsace(str.charAt(i)) == false)) {
return false;
}
}
return true;
}
}
(defn blank? [s] (every? #(Character/isWhitespace %) s))
public class Person {
private String firstName;
private String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
(defstruct person :first-name :last-name)
- 코드가 짧다
- 기본적으로 변경 불가능
- 괄호가 적은 Lisp
(cond ((< x 10) "less")
((> x 10) "more"))
(cond (< x 10) "less"
(> x 10) "more")
- 함수형 언어 (함수는 first-class object, 데이터는 변경 불가능, side effect가 없어야 한다.)
- 자바 라이브러리 사용가능
(.start (new Thread (fn [] (println "Hello"))))
clojure package manager
$ wget https://raw.github.com/technomancy/leiningen/stable/bin/lein
$ chmod +x ./lein
# path 잡기, lein은 script파일, 본인의 적당한 path에 lein파일을 위치시켜주면 ok
# mv ./lein [path]
$ mv ./lein ~/bin
clojure ==> todd 요건 뭘 의미하는 거죠...ㅋㅋ
$ lein repl
(println "hello world")
user=> (defn hello [name] (println (str "hello " name "!")))
#'user/hello
user=> (hello "clojure")
hello clojure!
nil
leiningen project template
vi ~/.lein/profiles.clj
{:user {:plugins [[compojure/lein-template "0.3.5"]]}}
lein
lein new compojure-app project-name
lein ring server
- emacs
- Light Table (http://www.lighttable.com/)
HTTP 라이브러리
https://github.com/ring-clojure/ring
HTTP 라우팅 라이브러리
https://github.com/weavejester/compojure
간단한 템플릿
https://github.com/weavejester/hiccup
세션, 암호화, 업로드
https://github.com/noir-clojure/lib-noir
RESTful API 라이브러리
http://clojure-liberator.github.io/liberator/
PDF 만드는 라이브러리
https://github.com/yogthos/clj-pdf
로깅
https://github.com/ptaoussanis/timbre
템플릿 엔진
https://github.com/yogthos/Selmer
SQL DSL