This file contains 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
(defn map-keys | |
"Applies f to all keys of m recursively." | |
[f m] | |
(cond | |
(map? m) (into {} (map (fn [[key value]] | |
[(f key) (map-keys f value)]) | |
m)) | |
(coll? m) (map (partial map-keys f) m) | |
:default m)) |
This file contains 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
;; Step 1: Follow steps from http://tromey.com/elpa/install.html and install `swank-clojure'. | |
;; Step 2: mkdir ~/.emacs.d.clj | |
;; Step 3: mv ~/.emacs ~/.emacs.d/init.el | |
;; Step 4: Copy swank-clojure, slime, slime-repl & clojure-mode directories from `~/.emacs.d/elpa/' to `~/.emacs.d.clj/' | |
;; Step 5: Create an `init.el' file in `~/.emacs.d.clj' directory | |
;; Step 6: mkdir -p ~/clojure-project/{lib,classes,src} | |
;; Step 7: cd ~/clojure-project/lib | |
;; Step 8: wget -cv http://build.clojure.org/snapshots/org/clojure/clojure/1.1.0-master-SNAPSHOT/clojure-1.1.0-master-20091231.150150-10.jar | |
;; Step 9: wget -cv http://build.clojure.org/snapshots/org/clojure/clojure-contrib/1.1.0-master-SNAPSHOT/clojure-contrib-1.1.0-master-20100114.180141-21.jar | |
;; Step 10: wget -cv http://repo.technomancy.us/swank-clojure-1.1.0.jar |
This file contains 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
;;; http://clojure.googlegroups.com/web/tutorial.pdf | |
;;; Vector binding forms destructure sequential things (vectors, lists, seqs, strings, arrays, | |
;;; and anything that supports nth) | |
;;; Map binding forms destructure associative things (maps, vectors, strings and arrays; | |
;;; the latter three have integer keys) | |
user> (let [[a b c] "xyz"] | |
[a b c]) |
This file contains 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
user> (re-seq (re-pattern #"\bfoo\b") "bar foo bar") | |
("foo") | |
user> (def *s "foo") | |
#'user/*s | |
user> (re-seq (re-pattern (format "\b%s\b" *s)) "bar foo bar") | |
nil | |
user> (re-seq (re-pattern (format "\\b%s\\b" *s)) "bar foo bar") | |
("foo") | |
user> |
This file contains 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
(defn map-keys | |
"Applies f to all keys of m recursively." | |
[f m] | |
(cond | |
(map? m) (into {} (map (fn [[key value]] | |
[(f key) (map-keys f value)]) | |
m)) | |
(coll? m) (map (partial map-keys f) m) | |
:default m)) |
This file contains 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
;; This buffer is for notes you don't want to save, and for Lisp evaluation. | |
;; If you want to create a file, visit that file with C-x C-f, | |
;; then enter the text in that file's own buffer. | |
This file contains 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
;; First fetch CVS version of slime, git version of clojure, swank-clojure, clojure-contrib and clojure-mode | |
;; Create ~/bin/clojure script which starts clojure repl and adds clojure-contrib src dir and swank-clojure src dir to classpath. I used clj-env helper from clojure-contrib | |
(pushnew '("\.clj$" . clojure-mode) auto-mode-alist) | |
(require 'clojure-mode) | |
;;;; Slime configuration stuff | |
(setf slime-lisp-implementations | |
'((ecl("~/bin/ecl" "--heap-size" "1024000000") :coding-system utf-8-unix) |
This file contains 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
(ns practical-clojure.chapter4 | |
(:require [clojure.contrib [duck-streams :as ccds]])) | |
(def my-matcher (re-matcher #"[a-zA-Z]*" "test")) | |
(def my-matcher2 (re-matcher #"[a-z]" "test")) | |
;;; practical-clojure.chapter4> (find-all-matches #"\d" (apply str (range 10))) | |
;;; ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"] | |
(defn find-all-matches [re string] |
This file contains 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
user> (def *files* (file-seq (java.io.File. "/tmp"))) | |
#'user/*files* | |
user> (def *f* (first *files*)) | |
#'user/*f* | |
user> *f* | |
#<File /tmp> | |
user> (.isFile *f*) | |
false | |
user> (.isDirectory *f*) | |
true |
This file contains 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
(defn plus | |
([x] ((fnil + 0) x)) | |
([x y] | |
((fnil + 0 0) x y)) | |
([x y z] | |
((fnil + 0 0 0) x y z)) | |
([x y z & more] | |
(reduce plus (plus x y z) more))) | |
;; user> (plus nil) |
OlderNewer