본문 바로가기

프로그래밍 언어 노트/Clojure

(28)
[Clojure 연습] 3. 4Clojure Elementary 클로저에 관한 빈칸 채우기 문제 사이트 4Clojure 차근 차근 풀어봐야겠다 ㅜ 문제 # 4 답 :a :b :c 문제 # 6 vector 답 :a :b :c 해설 why: = 연사자는 뒤의 파라미터들이 모두 같은지 판단한다, 또한 list 와 vector는 같은 요소라면 같다고판별 문제 # 8 set 답 #{:a :b :c :d} 문제 # 10 답 20 해설 (맵 key) 혹은 (key 맵) 은 해당 value 문제 #12 답 3 문제 #14 function 답 8 해설 #(함수) 에서 %는 처음 파라미터를 의미함 2개이상이면 %1 %2 .. Partial 은 모르것다. 문제 #16 hello world 답 #(str "Hello, " % "!") 문제 # 18 filter function 답 '(6 ..
[Clojure 연습] 2. 기초 연습문제 (ns hello.core) (def user-data {"id" 10, "name" "jack", "age" 0, "role" :developer}) (def users [user-data (assoc user-data "role" :tester "age" 20) (assoc user-data "age" 10)]) ; 재귀(defn sum-developer-age [init-user] ((fn [v sum] (if (empty? v) sum (recur (rest v) (+ sum (get (first v) "age"))))) init-user 0)) ;시퀀스 함수(defn sum-developer-age-sq [init-user] (reduce + (map (fn [i] (get i "age")) i..
[Clojure] read-line을 통하여 값을 읽을때 print보다 먼저 불리는 현상 해결방안: https://stackoverflow.com/questions/388057/clojure-side-effects-happening-out-of-order (flush 를 이용) (defn input [] (print "Type! :") (let [x (read-line)] (println (str "InputValue is:" x)) )) (input)이런상황에서보통의 C++ C# java ...기타등등 언어라면 당연히 Type: 이 출력되고그다음 x를 입력받고그다음InputValue is : 10" 이런식으로 출력되어야하는데 실행시키면 read-line이 먼저실행되고 그다음 Type!: InputValue is 10 이런식으로 출력이된다. aaaaa Type! :InputValue is:a..
[Clojure 연습] 1. 기초 연습문제 (ns hello.core) (defn Hello-Name [args] (println (str "hello " (first args))) ) (defn My-Calc-Program [] (let [x (Long/parseLong (read-line)) y (Long/parseLong (read-line)) z (read-line)] (case z "+" (println (+ x y)) "-" (println (- x y)) "*" (println (* x y)) "/" (println (/ x y)) ) )) (defn Sum-All [args] (println (apply + (map #(Long/parseLong %) args )) ) ) (defn -main [& args] (Sum-All arg..