Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Clojure1.4 Reader Literals Test
(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"
{
?= myreader.core/debug-print
str myreader.core/expand-sexp
}
@ericnormand

It should be noted that top-level reader literals are reserved. You should use a namespace for your reader names. For instance #mynamesspace/str

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.