Differences

This shows you the differences between two versions of the page.

Link to this comparison view

language:clojure [2018/02/19 02:12] ledyxlanguage:clojure [2021/02/07 03:15] (current) – external edit 127.0.0.1
Line 4: Line 4:
 https://clojure.org/guides/learn/syntax https://clojure.org/guides/learn/syntax
  
-{{tag>Language Clojure JVM}}+{{tag> clojure functional_programming jvm language }}
  
  
Line 15: Line 15:
     * Mac : http://www.hildeberto.com/2015/07/installing-leiningen-on-mac-os.html     * Mac : http://www.hildeberto.com/2015/07/installing-leiningen-on-mac-os.html
       * 사전에 [[https://brew.sh/index_ko.html|brew]] 설치 필요       * 사전에 [[https://brew.sh/index_ko.html|brew]] 설치 필요
 +    * Linux <sxh bash>
 +#java8
 +sudo add-apt-repository ppa:webupd8team/java
 +sudo apt-get update
 +sudo apt-get install oracle-java8-installer
 +
 +#leiningen
 +wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
 +chmod a+x lein
 +sudo mv lein /usr/local/bin
 +</sxh>
  
  
Line 165: Line 176:
 </sxh> </sxh>
  
 +===== Queue =====
 +<sxh>
 +(conj '(1 2 3) 4) ;; (4 1 2 3)
 +(pop '(1 2 3 4)) ;; (2 3 4)
 +(peek '(1 2 3 4)) ;; 1
 +</sxh>
  
 ==== Vectors ==== ==== Vectors ====
Line 193: Line 210:
 (conj [1 2 3] 4) (conj [1 2 3] 4)
 => [1 2 3 4] => [1 2 3 4]
 +</sxh>
 +
 +
 +===== Stack =====
 +<sxh>
 +(conj [1 2 3] 4) ;; [1 2 3 4]
 +(pop [1 2 3 4]) ;; [1 2 3]
 +(peek [1 2 3 4]) ;; 4
 </sxh> </sxh>
  
Line 565: Line 590:
 </sxh> </sxh>
  
-<sxh ; title:나머지 변수 이용. 이해하지 못하는 코드>+<sxh ; title:Collecton의 인자 Binding>
 (def my-vector ["A" "B" "C" "D"]) (def my-vector ["A" "B" "C" "D"])
  
Line 590: Line 615:
 ;단순 재귀 ;단순 재귀
 ;;StackOverFlow ;;StackOverFlow
-(defn factorial1 [n result]+(defn factorial1 [n]
   (if (= n 1)   (if (= n 1)
-    result +    n 
-    (factorial1 (dec n) (*' result n))))+    (*' n (factorial (dec n)))))
  
-(factorial1 10000 1)+(factorial1 99999)
  
  
Line 935: Line 960:
 => 24 => 24
 </sxh> </sxh>
 +
 +
 +==== 함께 구현되는 Interface ====
 +
 +참고로 익명 함수에는 4개의 Java Interface가 Implement 된다.
 +
 +* java.util.concurrent.Callable
 +* java.lang.Runnbale
 +* java.io.Serializable
 +* java.util.Comparator 
 +
 +
 +https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/AFunction.java
 +https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java
 +
 +
  
 ==== Returing Functions ==== ==== Returing Functions ====
-  * Clojures : 함수 범위 안에 속하는 모든 변수에 접근할 수 있는 영역+  * Closures : 함수 범위 안에 속하는 모든 변수에 접근할 수 있는 영역
  
 <sxh> <sxh>
Line 1381: Line 1422:
  
   * <nowiki>(-> x forms)</nowiki>   * <nowiki>(-> x forms)</nowiki>
-    * forms에 x를 연쇄적으로 두 번째 아이템으로써 뒤에 삽입.+    * forms에 x를 연쇄적으로 맨 처음 아이템으로써 뒤에 삽입.
   * 함수를 여러번 중첩하는 경우 유용.   * 함수를 여러번 중첩하는 경우 유용.
  
Line 1402: Line 1443:
  
   * <nowiki>(->> x forms)</nowiki>   * <nowiki>(->> x forms)</nowiki>
-    * forms에 x를 연쇄적으로 첫 번째 아이템으로써 앞에 삽입.+    * forms에 x를 연쇄적으로 맨 마지막 아이템으로써 앞에 삽입.
   * Collections를 마지막 argument로 받는 함수들에 유용   * Collections를 마지막 argument로 받는 함수들에 유용
  
Line 1426: Line 1467:
 == DOM의 Value를 가져오는 방법 == == DOM의 Value를 가져오는 방법 ==
 <sxh> <sxh>
-(-> .-target .-value)+(-> .-target .-value)
 </sxh> </sxh>
  
language/clojure.1519006371.txt.gz · Last modified: 2021/02/07 03:15 (external edit)