git » homepage.git » master » tree

[master] / archive / forums / hacker-news / raw / items / 8926982.json

{"by":"wooby","id":8926982,"parent":8925690,"text":"This was a great example, and I think you are absolutely right that it\nis the identical in function, if not in form, to mine.<p>Interestingly, in the course of concocting a counter-counter example,\nI came up with this in an effort to show the two dynamic variables we\nstipulate - <i>host</i> and <i>target</i> - were absolutely required:<p><pre><code>    #+clj\n    (defmacro my-macro []\n      (cond\n        (contains? *features* :clj)  `(some-clojure-thing)\n        (contains? *features* :cljs) `~(do (require &#x27;some-ns)\n                                           ((resolve &#x27;some-ns&#x2F;some-fn)))))\n</code></pre>\nMy hope was to make the point that &#x27;some-ns&#x2F;some-fn would run in a\ncontext where (<i>features</i> :cljs) is true - as it is in the caller&#x27;s\n(macro body) environment - which would result in the system attempting\nto run ClojureScript code, which would explode because the macro is\nClojure.  Then I realized that require runs load, and load is in the\nmacro body.  The load&#x2F;require available in the environment is\nClojure-specific!  Thus, load&#x2F;require can bind disj :cljs and conj\n:clj before reading and compiling some-ns.<p>My counter-example failed, but did bring me a little closer to the\ntruth - that we only need one dynamic variable, <i>platform</i>.  Any\nplatform that has the ability to load code also has an opportunity to\nbind <i>platform</i> and thereby inform macros of target.  This simplifies\nthe Feature Macro proposal by half and we are excited to amend it.<p>Our updated cross-platform example becomes:<p><pre><code>    (case-platform\n      :cljs nil\n      :clj (defmacro my-macro []\n          (condp = *platform*\n            :clj  `(some-clojure-thing)\n             :cljs `(some-cljs-thing))))\n</code></pre>\nInstead of <i>host</i> and <i>target</i>, we are down to just <i>platform</i>.  We\ncontinue to see no need for a <i>features</i> set because of Clojure&#x27;s\nplatform-symbiosis.","time":1421890422,"type":"comment"}