体会lisp的同像性. lisp 从字符串 转为 runtime 的数据结构. 代码是数据 数据是代码
(ns cfenxi.core-test
(:require [clojure.test :refer :all]
[cfenxi.core :refer :all]
[clojure.walk :as w])
(:import (clojure.lang Compiler$C))
)
(defn study-read
"Lisp reader 的时候,会把字符 根据规则解析成 data 具体类型是 java 定义的.
Symbol PersistentList String MapEntry PersistentArrayMap
Keyword PersistentList
"
[str]
(let [r (read-string str)]
(w/prewalk (fn [x] (prn x (type x)) x) r)
;(w/prewalk-demo r)
)
)
输出
(study-read "(+ 3 2)")
(study-read "(fn [x] (do {:a x}))")
Loading test/cfenxi/core_test.clj...
(+ 3 2) clojure.lang.PersistentList
+ clojure.lang.Symbol
3 java.lang.Long
2 java.lang.Long
(fn [x] (do {:a x})) clojure.lang.PersistentList
fn clojure.lang.Symbol
[x] clojure.lang.PersistentVector
x clojure.lang.Symbol
(do {:a x}) clojure.lang.PersistentList
do clojure.lang.Symbol
{:a x} clojure.lang.PersistentArrayMap
[:a x] clojure.lang.MapEntry
:a clojure.lang.Keyword
x clojure.lang.Symbol
Loaded
网友评论