Import Record Type in Clojure/ClojureScript -
is there way import record type, works in clojure clojurescript? far can tell it's (ns x (:import y [a b]))
clojure, (ns x (:require y :refer [a b]))
clojurescript, , each invalid respective other.
ignoring specifics on syntax of requiring records, there 2 main ways write ns declarations (or platform specific code) multiple clojure variants while sharing majority of code.
cljx clojure preprocessor runs before clojure compiler. write platform specific code prefixed
#+clj
or#+cljs
in.cljx
file. can run on pretty clojure code, , spit out multiple platform specific files respective clojure compilers can handle.reader conditionals feature in clojure 1.7 , available in recent releases of clojurescript. similar in spirit cljx, integrated clojure compiler. write code reader conditionals
#?(:clj 1 :cljs 2)
in files.cljc
extension.
now specific question, can achieve reader conditionals so:
(ns myapp.music-store (:require #?(:clj [myapp.cool-music] :cljs [myapp.cool-music :refer [vinyl]])) #?(:clj (:import [myapp.cool_music vinyl])))
i wrote longer blog post too: requiring records in clojure , clojurescript
Comments
Post a Comment