Created
April 16, 2012 14:54
-
-
Save liquidz/2399254 to your computer and use it in GitHub Desktop.
Clojure1.4 Reader Literals Test
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
(ns myreader.core | |
"Reader Literals Test" | |
(:require [clojure.string :as str])) | |
(defn debug-print | |
"Gauche debug print" | |
[x] | |
`(let [res# ~x] | |
(println "?=" res#) | |
res#)) | |
(defn expand-sexp | |
"Expand S-exp in string" | |
[s] | |
(let [ls (map-indexed #(if (even? %) %2 (read-string %2)) | |
(str/split s #"`"))] | |
`(apply str (list ~@ls)))) | |
(defn -main [] | |
(println (map inc #?=(range 10))) | |
; ?= (0 1 2 3 4 5 6 7 8 9) | |
;=> (1 2 3 4 5 6 7 8 9 10) | |
(let [i 100] | |
(println #str"i = `i`") | |
;=> "i = 100" | |
(println #str"(+ 1 2 3) = `(+ 1 2 3)`"))) | |
;=> "(+ 1 2 3) = 6" |
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
{ | |
?= myreader.core/debug-print | |
str myreader.core/expand-sexp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It should be noted that top-level reader literals are reserved. You should use a namespace for your reader names. For instance
#mynamesspace/str