This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; simple | |
| (defn factorial [n] | |
| (if (zero? n) | |
| 1 | |
| (* n (factorial (dec n))))) | |
| ;; tail recursion | |
| (defn factorial | |
| ([n] (factorial n 1)) | |
| ([n sum] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /target | |
| /lib | |
| /classes | |
| /checkouts | |
| pom.xml | |
| pom.xml.asc | |
| *.jar | |
| *.class | |
| .lein-deps-sum | |
| .lein-failures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (declare ^:dynamic *asdf*) | |
| (let | |
| [b (binding [*asdf* 10] | |
| (for [i (range 0 3)] | |
| (* *asdf* i)))] | |
| b) | |
| ;;; => java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be cast to java.lang.Number | |
| (let |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # named pipe ็ๆ๏ผ | |
| mkfifo hoge_pipe | |
| # ๅฎ้ใซใใฎใใกใคใซใๅญๅจใใฆใใ | |
| ls -l hoge_pipe | |
| # named pipe ใใใฎๅ ฅๅใฎ่กๆฐใๆธฌใใใใซใปใใใฃใณใฐ | |
| wc -l < hoge_pipe & |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # bash executes this incorrectly. | |
| # On the other hand zsh executes this correctly. | |
| # Because bash spawns a sub-shell inside while-do loop meanwhile zsh doesn't it. | |
| declare -i sum | |
| seq 0 10 | while read num ; do | |
| let sum+=$num | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| foldl(){ | |
| local func="$1" | |
| local prev="$2" | |
| while read cur ; do | |
| prev="$(eval $func "$prev" "$cur")" | |
| done | |
| echo $prev | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| seq 0 10 | { | |
| declare -i sum | |
| while read num ; do | |
| let sum+=$num | |
| done | |
| # bash => 55 (^^)v | |
| # zsh => 55 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; call/cc ใ็่งฃใใใ๏ผ | |
| ;; ไธ่ฆใใใจๆฎ้ใซใใใฌใใฆใใ | |
| (call/cc (lambda (c) "Just invoke")) ; "Just invoke" | |
| (define boundval (call/cc (lambda (c) "Just invoke"))) | |
| boundval ; "Just invoke | |
| ;; ใ ใโฆ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun dividable (n m) | |
| (= (mod n m) 0)) | |
| (dividable 6 3) ; => t | |
| (dividable 6 4) ; => nil | |
| (defun euler-1 (begin end) | |
| (loop for i from begin to (1- end) | |
| sum (if (or (dividable i 3) (dividable i 5)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun parent-directory (dir) | |
| (unless (equal "/" dir) | |
| (file-name-directory (directory-file-name dir)))) | |
| (defun find-nearest-file (dir-path filename) | |
| (let ((file (concat dir-path filename)) | |
| (parent (parent-directory (expand-file-name dir-path)))) | |
| (if (file-exists-p file) | |
| file | |
| (when parent |