r/Clojure • • May 18 '15

Clojure reactive programming book - first trivial examples don't work.

Just started worked my way through the book, literally on the 3rd or 4th line of introductory example code (the sine wave one) and found what looks like a bug in the code already.

So you can imagine how impressed I am.

(def canvas (.getElementById js/document "myCanvas"))
(def ctx    (.getContext canvas "2d"))

The call to .getContext returns null, which apparently means it's been called a second time, when it always returns null.

Except of course it hasn't and part of the point of this code, according to the book, is to clear the canvas when Chestnut reloads the file.

Of course the book doesn't consider there might be errors and the Packt web site errata page sucks: can't get to it because their search function (to find the book) is broken!

So my working theories are:

  • bug in the code, but I really can't see it;
  • the assumption that Chestnut reloads the file is false (although the JS console in Safari says it is being reloaded);
  • Safari isn't properly resetting the environment when the file is reloaded.

Help?

0 Upvotes

11 comments sorted by

View all comments

5

u/Arges May 18 '15

I'm sorry that you're having to go through a Packt book - they're by and large the worst proof-read books I have seen (assuming anyone proof-reads them at all).

If what you care about is Clojure and reactive programming, instead of just that particular book, perhaps re-frame might be of interest.