Fork me on GitHub
#beginners
<
2016-08-05
>
jswart00:08:52

your JS doesn’t return a value. you run one function for its side-effect. In clojurescript all functions return values so that is why it returns the value of calling the function.

jswart00:08:20

if you call your CLJS callback function and don’t do anything with the value you have done essentially “the same thing”.

jswart00:08:41

You could alter the CLJS to get the compiled JS to look more similar but I don’t see why

jswart00:08:12

the only thing I can think of to get it to match would be to do something like (defn callback [] (do (js/Acad.Editor.executeCommand "_erase" "all" “") nil)) not exactly sure how that would compile but its semantic goal to what you wrote in JS is similar.

jswart00:08:50

I would read up on Statements vs. Expressions. In clojure there aren’t really statements, but you can make expressions that return no helpful value if you want I suppose.

shaun-mahood01:08:42

@jswart: Thanks, I'll try that. The API I'm using in JS expects a JS function and doesn't seem to work with the return value there. It's funny, I'm pretty comfortable when it's all cljs, and pretty comfortable when it's all js, but the interop still just throws me off.

jswart01:08:07

np! good luck.

jswart01:08:15

i have plenty of mishaps with that myself

zzamboni12:08:06

@guano, @abhishekamralkar : I almost-finished reading #C0M8PCF7U when I felt I needed more hands-on experience, so I started working through the 4clojure exercises, it's been a great progression. I'm at problem #96 now. Even though they are still "toy problems", they have helped a lot in getting a better handle on the standard Clojure functions, and on how to structure pieces of code slightly more complex than the #C0M8PCF7U end-of-chapter exercises.

abhishekamralkar12:08:58

This is great! @zzamboni . Thanks once again.

rattboi21:08:58

I'm curious how I might refactor this so that I don't have both calls to do-node-status

rattboi21:08:32

(defn node-status [amx env & node-names]
  (if-let [nodes node-names]
    (do-node-status amx env nodes)
    (let [nodes (list-nodes amx env)]
      (do-node-status amx env nodes))))

rattboi21:08:38

if you call it via (node-status amx env), it gets the nodes via list-nodes, but if you pass anything along, it uses that as the nodes

dg22:08:56

Maybe something along these lines?

(defn node-status
  ([amx env] (apply node-status amx env (list-nodes amx env)))
  ([amx env & nodes] (do-node-status amx env nodes)))

dg22:08:38

Though it doesn't feel great to have this function to little more than wrap another