public
Created

Clojure1.4 Reader Literals Test

  • Download Gist
core.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(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"
data_readers.clj
Clojure
1 2 3 4
{
?= myreader.core/debug-print
str myreader.core/expand-sexp
}

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.