This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-07
Channels
- # announcements (38)
- # asami (14)
- # beginners (35)
- # biff (3)
- # calva (29)
- # cider (20)
- # clj-kondo (7)
- # cljdoc (38)
- # clojure (64)
- # clojure-art (2)
- # clojure-australia (1)
- # clojure-dev (6)
- # clojure-europe (30)
- # clojure-nl (4)
- # clojure-spec (4)
- # clojure-uk (9)
- # clojured (3)
- # clojurescript (87)
- # cursive (17)
- # datahike (2)
- # datomic (10)
- # defnpodcast (2)
- # emacs (2)
- # events (1)
- # fulcro (25)
- # gratitude (1)
- # introduce-yourself (1)
- # jobs-discuss (21)
- # lsp (103)
- # malli (41)
- # meander (8)
- # minecraft (3)
- # missionary (3)
- # nextjournal (20)
- # off-topic (10)
- # pedestal (1)
- # polylith (15)
- # portal (6)
- # releases (2)
- # ring (1)
- # ring-swagger (2)
- # sci (4)
- # shadow-cljs (5)
- # spacemacs (3)
- # sql (11)
- # xtdb (3)
Thank you so much phronmophobic.
I didn't get an error message
I'm running my code in Clojupyter. I tried it in Calva as well, and didn't notice an error there either. How are you running the code?
I copied that 0-arity version from Tim Baldridge's 2013 presentation: https://github.com/halgari/clojure-conj-2013-core.async-examples/blob/master/src/clojure_conj_talk/core.clj
I am not aware of that callback ever not taking am argument, but I had recent patch that fixed something deep in the bowels of core.async where it was attaching callbacks that took zero args, so maybe that was the case at one point
Thanks hiredman - it was a very old presentation, so I'm sure it's because things have changed.
I noticed some clojurescript projects have clj files, and some don't. For example, projects made with luminus have clj files. But projects made with figwheel don't, it's only cljs files. Why is this?
If you’re using macros of any form, they must be written in Clojure. The cljs compiler uses the clojure to expand the macros first, then transpiles the cljs to js
Ok so it sounds like, for the tutorials I've done that are only in cljs it's ok because there aren't any macros, but for a real production application, it would probably use clojure & cljs?
I'm a newbie but I'd assume that a real-world application, like a facebook or youtube clone would use some kind of macros right? Or not necessarily?
not necessarily used, macros are a sharp tool, can do awesome stuff but also lead to hard to debug issues if not used carefully. You can mix clojure and clojurescript in a codebase using .cljc, where you can use reader conditionals to say how to evaluate the code depending on the platform reading the file. Many cljs codebases indeed still have .clj files because if you want to use macros in cljs the jvm is still needed because they run at compile time.
however, I think luminus is a project that uses clojure and clojurescript. So perhaps the .clj files there are just clojure?
Yes, Luminus has .clj files, and cljc files, and cljs files. Is that normal for a big production application? What I'm trying to understand, is that I've been doing some clojurescript tutorials that use figwheel, and these projects don't have any clj or cljc files. Only cljs. Is that normal, or does it only really happen for little tutorial type apps? :thinking_face:
For example, if I want to create a facebook clone, would I have to use clj, cljc and cljs in my final production ready code? Or would it be possible to create something so complicated with only cljs files, similar to the little tutorials I've done with figwheel?
If you’re running full-stack clojure, then you’ll probably have a mix of all. If you’re only using it for frontend work, you’ll have mostly cljs files, with a couple clj files around for macros/occasional other scripts
Cool, thanks
Yup -- there's absolutely no downside of starting simple with just .cljs files. If you need to write macros/scripts at some point, you can add some .clj files then 🙂
(condp
=
(type my-err)
clojure.lang.ExceptionInfo
'fa
'fo)
;; => fa
(case
(type my-err)
clojure.lang.ExceptionInfo
'fa
'fo)
;; => fo
why is it different and is there a better way?case
doesn't evaluate the test expressions, so it gets clojure.lang.ExceptionInfo
as a symbol, while type
returns a Class. You could get the same behavior by using (symbol (type my-err))
But I think it's clearer to use cond
or (condp = ,,,)
as in your first example for these kinds of expressions where you're checking the type of a value
Just a correction on the above: to get a symbol from a Class you need to do (symbol (.getName (type x)))
. You could do (case (.getName (type x)) "clojure.lang.ExceptionInfo" ,,,)
with strings as the test constants, but I still think that (cond (instance? clojure.lang.ExceptionInfo x) ,,,)
is clearer
Does clojure have some process to run in debug mode and step through execution?
I've found the Cider debugger very easy to use. I also use the Cider Inspector to help me understand issues, especially when I need to navigate or page through large results. This can save the need for specific debugging https://practical.li/spacemacs/debug-clojure/ Portal is an editor agnostic way to also navigate larger results
You can also implement a custom support dor a primitive debug repl - an example of that is in Joy of Clojure
Kinda like I would in Java or python?
set break points, run my app, hit a url and then I enter debug mode and step through the request.
several Clojure dev environments provide debuggers - Cursive and CIDER at least
good to hear, I think most folks around here use cursive.
see #cursive if you have questions... I use Cursive for this all the time (because I typically do a lot of Java/Clojure interop and you can step through both easily). You do have to keep in mind that a single line of Clojure may expand to a lot of bytecode so "stepping" leaves you in the same line many times in a row. but you can use breakpoints, evaluate Clojure expressions at a breakpoint, etc
Curious, what have been your primary obstacles/blockers or tedious/annoying stuff when doing Java interop?
I've found the Cider debugger very easy to use. I also use the Cider Inspector to help me understand issues, especially when I need to navigate or page through large results. This can save the need for specific debugging https://practical.li/spacemacs/debug-clojure/ Portal is an editor agnostic way to also navigate larger results