Note that there are some explanatory texts on larger screens.

plurals
  1. POusing -?> in Clojurescript?
    text
    copied!<p>In my Clojure shared source, I have the following (which I shamelessly stole):</p> <pre><code>(defmacro hey-str [name] `(str "hey " ~name)) {:author "Laurent Petit (and others)" :doc "Functions/macros variants of the ones that can be found in clojure.core (note to other contrib members: feel free to add to this lib)"} (defmacro- defnilsafe [docstring non-safe-name nil-safe-name] `(defmacro ~nil-safe-name ~docstring {:arglists '([~'x ~'form] [~'x ~'form ~'&amp; ~'forms])} ([x# form#] `(let [~'i# ~x#] (when-not (nil? ~'i#) (~'~non-safe-name ~'i# ~form#)))) ([x# form# &amp; more#] `(~'~nil-safe-name (~'~nil-safe-name ~x# ~form#) ~@more#)))) (defnilsafe "Same as clojure.core/-&gt; but returns nil as soon as the threaded value is nil itself (thus short-circuiting any pending computation). Examples : (-?&gt; \"foo\" .toUpperCase (.substring 1)) returns \"OO\" (-?&gt; nil .toUpperCase (.substring 1)) returns nil " -&gt; -?&gt;) (defnilsafe "Same as clojure.core/.. but returns nil as soon as the threaded value is nil itself (thus short-circuiting any pending computation). Examples : (.?. \"foo\" .toUpperCase (.substring 1)) returns \"OO\" (.?. nil .toUpperCase (.substring 1)) returns nil " .. .?.) (defnilsafe "Same as clojure.core/-&gt;&gt; but returns nil as soon as the threaded value is nil itself (thus short-circuiting any pending computation). Examples : (-?&gt;&gt; (range 5) (map inc)) returns (1 2 3 4 5) (-?&gt;&gt; [] seq (map inc)) returns nil " -&gt;&gt; -?&gt;&gt;) </code></pre> <p>In my Clojurescript code I have the following (I :require-macros as c)</p> <pre><code>(def a nil) (def b []) (def c [{:a 23}]) (js/alert (c/hey-str "Stephen")) ;; should display "hey Stephen" (js/alert (c/-?&gt; a first :a)) ;; should display nil (js/alert (c/-?&gt; b first :a)) ;; should display nil (js/alert (c/-?&gt; c first :a)) ;; should display 23 </code></pre> <p>Unfortunately, when I compile, I get:</p> <pre><code>WARNING: Use of undeclared Var webstack.client/-?&gt; at line 56 cljs-src/webstack/client.cljs WARNING: Use of undeclared Var webstack.client/-?&gt; at line 57 cljs-src/webstack/client.cljs WARNING: Use of undeclared Var webstack.client/-?&gt; at line 58 cljs-src/webstack/client.cljs </code></pre> <p>When I open the javascript in a browser, I get the "hey Stephen" alert dialog, but the ubiquitous "Uncaught TypeError: Cannot call method 'call' of undefined" error comes up immediately after pressing "ok" on the "hey Stephen" alert. Sure enough, looking at the generated javascript code, my js/alert's became:</p> <pre><code>alert([cljs.core.str("hey "), cljs.core.str("Stephen")].join("")); alert(webstack.client.__QMARK__GT_.call(null, webstack.client.__QMARK__GT_.call(null, webstack.client.a, cljs.core.first), "\ufdd0'a")); alert(webstack.client.__QMARK__GT_.call(null, webstack.client.__QMARK__GT_.call(null, webstack.client.b, cljs.core.first), "\ufdd0'a")); alert(webstack.client.__QMARK__GT_.call(null, webstack.client.__QMARK__GT_.call(null, webstack.client.c, cljs.core.first), "\ufdd0'a")) </code></pre> <p>So clearly, I can use macro's, but something about the way the -?> (and related) macros are written causes them to fail to compile. What do I need to do in order to use these <code>-?&gt;</code> <code>.?.</code> and `-?>>' macros?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload