git » homepage.git » master » tree

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

{"by":"brandonbloom","id":8923776,"kids":[8923835,8926408],"parent":8923385,"text":"Many of the most useful applications of feature expressions simply will not work as macros. You&#x27;d need to create one new feature-cond enabled macro for each other macro use case. Feature expressions, on the other hand, are a general solution that can be used at the call site without having to reinvent every macro that may ever need platform-conditional behavior, like your ns+ macro.<p>Consider the proposed +clj form in the body of an extend-protocol or a deftype:<p><pre><code>    (defmacro +clj\n      &quot;Form is evaluated only in the JVM.&quot;\n      [form]\n      (when (= :clj *host*) form))\n\n\n    (deftype Foo\n\n      SomeCommonProtocol\n      (aMethod [blah blah] ...)\n\n      (+clj\n        JvmOnlyInterface\n        (someMethod [blah] ...)\n        )\n    \n      )\n</code></pre>\nOf course, this <i>does not work</i>. The deftype macro gets the +clj form unmodified and must handle it on its own.<p>At best, you could have a syntax-quote style wrapper form:<p><pre><code>    (feature-quote\n      (deftype Foo\n\n        SomeCommonProtocol\n        (aMethod [blah blah] ...)\n\n        (+clj\n          JvmOnlyInterface\n          (someMethod [blah] ...)\n          )\n\n        ))\n</code></pre>\nHowever, this is essentially what Feature Expressions are anyway. Only broken, since macros don&#x27;t only operate on syntax&#x2F;edn, they can operate on any compile-phase value, like dates and times or the output of any tagged literal handler. Without being part of the phase before the macro expander, you can&#x27;t prevent platform specific types from reaching the macro body.<p>The reality is that Clojure, in the tradition of most lisps, has rigid read&#x2F;compile&#x2F;run phase separation where each phase has a varied evaluation strategy, but the phases run interleaved. Unlike say something like Mathematica, which does not run the reader interleaved with the evaluator - and the evaluator uses normal-order rather than applicative-order! Without such a uniform evaluation strategy (nevermind Mathematica&#x27;s evaluator&#x27;s other problems) it simply doesn&#x27;t make sense to fight so hard against beefing up the read phase.<p>Related: I&#x27;ve written before about how I don&#x27;t think that this impacts tooling as badly as you guys thing it does. I just don&#x27;t understand why you guys are so against feature expressions, nor do I think you&#x27;ve succeeded in proposing a desirable alternative.","time":1421857685,"type":"comment"}