Live data from Hacker News

ClojureScript 101

swannodette.github.io

21–30 of 45 posts

Re: ClojureScript 101

#22

Hey swannodette, just curious about why you ended the tag in your tutorial. Was this deliberate?

Hmm, I seem to have found a limitation/bug in go blocks. I didn't know about the nifty "." syntax for calling methods on js objects, eg: (. js/console (log "hi")).

Anyway, I thought this was great, so I tried doing it inside of a go block, like so: (go (while true) (. js/console (log (And this yielded a compiler warning: WARNING: Use of undeclared Var async-tut1.core/log at line 50 src/async_tut1/core.cljs

So there seems to be a problem with namespace resolution and the go macro? Or maybe a bug with "." in particular? Works fine when I do (.log js/console (Either way, I would try to be consistent about your notation throughout the article. Either use (.log js/console ...) or use (. js/console (log ...)).

Core.async in the browser is a ton of fun otherwise! Kudos.

Re: ClojureScript 101

#23

Hey swannodette, just curious about why you ended the tag in your tutorial. Was this deliberate?

Hmm, I seem to have found a limitation/bug in go blocks. I didn't know about the nifty "." syntax for calling methods on js objects, eg: (. js/console (log "hi")). Anyway, I thought this was great, so I tried doing it inside of a go block, like so: (go (while true) (. js/console (log ( And this yielded a compiler warning: WARNING: Use of undeclared Var async-tut1.core/log at line 50 src/async_tut1/core.cljs So there…

(Even if this is a known limitation and not a bug, I would love to understand why one form works and the other does not.)

Re: ClojureScript 101

#24

Hey swannodette, just curious about why you ended the tag in your tutorial. Was this deliberate?

Hmm, I seem to have found a limitation/bug in go blocks. I didn't know about the nifty "." syntax for calling methods on js objects, eg: (. js/console (log "hi")). Anyway, I thought this was great, so I tried doing it inside of a go block, like so: (go (while true) (. js/console (log ( And this yielded a compiler warning: WARNING: Use of undeclared Var async-tut1.core/log at line 50 src/async_tut1/core.cljs So there…

I think this is a typo in the article. If you remove the parenthesis right before log, this should work. You're using the dot form to chain log onto js/console. When you write "(log" instead of just "log", it tries to call log as its own function, not as a method of js/console. This is why it tells you it's never seen that variable before.

(go (while true) (. js/console log (<! clicks)))

Re: ClojureScript 101

#27

Since this is supposed to be a 101 tutorial, could you please add (maybe in a later episode) some info on debugging and on parsing the stack trace. When I add the text 1+" to core.clsj and have auto compile running, I get a gigantic stack trace but none of the entries points me to the line where the error occured. I wonder how people are supposed to handle a code base bigger than a few lines of code and I stop follow…

Clojure stack traces in general are pretty verbose. A few thoughts from a fellow user (not ClojureScript specific, but remember we're doing all of this in a Clojure project):

The top few lines of the stack trace have the most information. Entering some blank space or clearing your terminal will make it easier to find the top.

The errors are often caught way down in Java land so you can be left trying to map Java errors and types into your own code - I've learned to ignore 80%+ of the trace for this reason.

There's a bit of a learning curve to figure out what this can't be cast to that might mean, both for Java types and Clojure types. For example a missing opening paren may give a (roughly) "number can't be cast to sequence" error. A missing closing paren will generally throw an End Of File (EOF) error.

A lot of the time you can get a line number from the top entry in the stack trace, they'll be in parentheses and aren't labeled terribly well - but once you find it once you'll know where it is forever.

Sometimes, in certain situations - especially with macros that call across files (like for testing) - the stack trace might be completely unhelpful.

I'm definitely hopeful that this situation will improve in the future (and maybe we can get an Edwin style debugger? Please?) In the meantime we can use tools to help us at least keep our braces organized since that's half the difficult to trace problems right there. For Emacs some swear by paredit, I'm still working on my system but it includes electric-parens, rainbow-parens (so helpful!) and auto-closing parens.

Also, it's not as robust as Emacs but Lighttable offers some decent parentheses handling out of the box (I went back to Emacs after Lighttable was making connections to outside servers that I at least didn't mean to ask it to and didn't have time to deal with. Other than that Lighttable was great).

Re: ClojureScript 101

#28

Since this is supposed to be a 101 tutorial, could you please add (maybe in a later episode) some info on debugging and on parsing the stack trace. When I add the text 1+" to core.clsj and have auto compile running, I get a gigantic stack trace but none of the entries points me to the line where the error occured. I wonder how people are supposed to handle a code base bigger than a few lines of code and I stop follow…

ClojureScript generally gives pretty good errors and location information, however there are probably cases still where that's not true. This is likely an issues with tools.reader? Thanks for the report, I'll ask around about getting this looked into.

Re: ClojureScript 101

#29

Hey swannodette, just curious about why you ended the tag in your tutorial. Was this deliberate?

Hmm, I seem to have found a limitation/bug in go blocks. I didn't know about the nifty "." syntax for calling methods on js objects, eg: (. js/console (log "hi")). Anyway, I thought this was great, so I tried doing it inside of a go block, like so: (go (while true) (. js/console (log ( And this yielded a compiler warning: WARNING: Use of undeclared Var async-tut1.core/log at line 50 src/async_tut1/core.cljs So there…

A bug in core.async, I've already opened a ticket for this. Thanks for the feedback!

Re: ClojureScript 101

#30
post #16
post #14

Great write up. ClojureScript 102 should be how to get a REPL running ;)

Could you please do one that explain how to actually debug in CLJS.

Debugging is a more straight forward now because of source maps, but it still needs a little bit of explaining - will think about it.
Post reply on HN