With read-string in Clojure, the :clj platform feature is always active but it is possible to add additional features like :cljs:
(read-string {:read-cond :allow, :features #{:cljs}} "#?(:clj 1 :cljs 2)") In this case, both :clj and :cljs features will be active, so it will return 1 because the read-cond checks in order. If you put the :cljs choice first, it would be taken. With tools.reader, you will not have this issue - you can use tools.reader to read with only the :cljs platform feature active. (require '[clojure.tools.reader :as r]) (r/read-string {:read-cond :allow, :features #{:cljs}} "#?(:clj 1 :cljs 2)") ;; 2 And this is exactly how ClojureScript reads (using tools.reader). On Thursday, July 19, 2018 at 12:44:57 AM UTC-5, Nikita Beloglazov wrote: > > Hi > > Is it possible to read a string containing reader conditionals using a > platform different from "current". In particular in from clojure I want to > read a string that contains :cljs reader conditionals and evaluate them as > if current platform is cljs. > > Example: if I run the following code from clj: > > (read-string {:read-cond :allow} "#?(:clj 1 :cljs 2)") > > then I get 1. But I want to get 2. Is there a way to do it in Clojure > somehow or maybe using tools.reader? > > Thanks, > Nikita > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.