reader - Clojure: How do I get the file/line number on which a map was defined? -


i know can :line , :file metadata on var; however, i'm building system user can pass me raw maps , end "linking" data @ later time. when linkage fails, i'd report file/line in specified map. e.g.:

 (defn generate-stuff []     (make-thing { :k (make-thing { :k v }) }     )  )   (link (generate-stuff) (other-generator))  ;; outputs file/line of map containing errant :k/v pair 

i assume writing macro associate file/line collection's metadata way go, since there isn't "var" at, i'm not sure line number. see definition of get-line-number, requires reader, , while can find of special readers , *default-data-reader-fn* data reader (which nil), cannot seem figure out how access "code" reader.

ok, looks using &form in macro answer. wrote following bit of generic test code, , seems work:

(defmacro make-thing [obj]   (let [f *file*]     (with-meta obj (assoc (meta &form) :file f))   ) ) 

the &form refers form invoked macro, , has metadata line/column. special var file has relative path of source file. so, combining 2 metadata onto object results in desired result.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -