Fork me on GitHub

Hi guys, I recently bought the Programming Clojure book and there is this code example

(defn preds-seq []
  (->> (all-ns)
    (map ns-publics)
    (mapcat vals)
    (filter #(clojure.string/ends-with? % "?"))
    (map #(str (.-sym %)))
But I am not sure what is the .-sym function, I couldn’t fine any docs about it. Does anyone has an idea what function is that? Thanks!

Alex Miller (Clojure team)13:12:33

.- is a Java interop call for field access

Alex Miller (Clojure team)13:12:53

. Is Java interop for either method or field access - if both exist, the method takes precedence. .- is field only.


Oh, I see. Thank you very much Alex 🙏

Alex Miller (Clojure team)15:12:42

since the book came out, there's a new arity of symbol that actually makes the field access here unnecessary

Alex Miller (Clojure team)15:12:47

(->> (all-ns) (map ns-publics) (mapcat vals) (filter #(clojure.string/ends-with? % "?")) (map symbol) vec)

Alex Miller (Clojure team)15:12:31

well almost - depends on whether you want symbols or strings at the end

Alex Miller (Clojure team)15:12:43

but no need for .- there regardless


Oh thank you very much!


that looks like clojurescript interop where .-xxx means read a property of xxx from the object


it's valid in all flavors of clojure, but it's more interesting in cljs because in clj the object can't have a method and property that share the same name (unlike cljs where it can)


thanks ... for some reason I only just noticed cos it's a thread reply


Hi, functions that cause side-effect are suffixed !, functions that accept varargs are suffixed *. Is there a convention for a function that is both?

Sam Ferrell08:12:59

i'm not certain function names suffixed with * have that meaning.

Sam Ferrell08:12:11

i'm not aware of any conventions for naming functions that accept var args


I saw someone use *name to describe an atom/ref/agent, and I've started to pick up that habit. It's not particularly widespread though

Sam Ferrell08:12:38

more often i've seen foo* being used to describe an "uglier" interface to foo but not private because it may still be useful to users

👍 4
Sam Ferrell08:12:38

regardless, you can name a function foo!* if you so desire


N00b clojurian here! I saw "Clojure cookbook" which I will definitely grab, but what would be the canonical book for the language itself (ideally with plenty of fp & lisp theory)? And any coljurescript books that are cookbook style? Any recommendations would be greatly appreciated!

Artur Aralin08:12:12

Does httpkit+compojure enough for developing rest api or I need use any framework?


@artur.aralin97 I think most people use "ring" certainly frameworks like fulcro

Artur Aralin10:12:28

@cam.asoftware why ring? httpkit looks pretty simple


@artur.aralin97 I hadn't used either, I'm new to Clojure. But what I do know is this; when learning a new technology, walk the path most travelled. With that many GitHub stars, adoption by popular frameworks/libraries tells me that's the best approach.

Alexander Moskvichev11:12:00

Hi guys. Please help. Trying to make my first project with clojurescript, but I'm stuck a bit with tooling. Started from this example Can't configure a stable dev environment, especially REPL. Can someone point me to a good tutorial? Or just name the right tools, I'm totally lost for now. (lein, boot, deps, figwheels, shadow-cljs, proto-repl, chlorine etc) I use windows 10 / java 11 (adopt-openjdk) and Ubuntu. Need setup for both.

Pavel Klavík11:12:00

If you want just clojurescript, you only need shadow-cljs.

Pavel Klavík11:12:40

I have build this example repo for my teammates, you can just clone it and follow the instructions:

Pavel Klavík11:12:17

For installing Shadow-cljs, you just need NodeJS (npm) and run npm install -g shadow-cljs.

Pavel Klavík11:12:52

I would also recommend to invest into some IDE with build in REPL support, we personally are using IntelliJ and Cursive and it is great.

Alexander Moskvichev11:12:44

Thank you, Pavel. Do you use IntelliJ+Cursive on Windows or Linux/mac?

Pavel Klavík11:12:38

I am running on Windows, my friend on Linux, no real difference

Alexander Moskvichev11:12:53

And also, does java version matter?

Pavel Klavík11:12:16

at least at the beginning

Alexander Moskvichev11:12:56

Ok, I'll try Cursive today. Thank you again.


Can somebody tell me, why the following code does not throw an exception?

  (for [x (range 4)]
    (throw (RuntimeException.)))


It results in nil afterwards

Pavel Klavík11:12:49

since its results are not used, they are never computed


You are totally right

Pavel Klavík11:12:03

if you want to run them, you can use (doall (for ...))

Pavel Klavík11:12:39

btw. for doing sideeffects, doseq is better


But the following still does not throw an exception:

  (for [x (range 4)]
    (throw (RuntimeException.)))

Pavel Klavík11:12:54

It is different:

  (doall (for [x (range 4)]
    (throw (RuntimeException.))))

Pavel Klavík11:12:13

Or just:

  (doseq [x (range 4)]
    (throw (RuntimeException.)))


Cool, thanks a lot !

Adrian Smith17:12:11

I've created a beginners guide for using Cursive and Intellji in Clojure: I created it for a local group I'm teaching but it might be useful to others, source code is in if you have improvements

👍 4

hey everyone. Is there a simple way I can use back tick without name space resolution (and without resorting to macros)? i.e. Instead of

`(fn [] ~(inc 1))
=> (clojure.core/fn [] 2)
=> (fn [] 2)


I could tree walk this and replace the fully resolved name with a simple name, but maybe there's a simpler way


I kept the example small, but there might be other symbols involved not just fn


i.e. I want a regular quote but with an unquote facility

Alex Miller (Clojure team)17:12:53

clojure.template ns is useful for this

👍 4
Alex Miller (Clojure team)17:12:49

Or you could just use ~‘fn in your example

👏 4

there are also some libraries


thank you so much!

Prakash Venkat18:12:46

hey everyone. anyone have opinions on an emacs distribution that will work on linux?

Prakash Venkat18:12:54

is spacemacs a good call?


If you like vim, it is.


other than that, your linux distro should already have emacs

Prakash Venkat18:12:07

oh, but i want one with all the clojure/lisp stuff prepackaged

Prakash Venkat18:12:35

preferabbly one that feels like atom/vscode (my original goal was to clojure without emacs at all. that doesnt look likely or practical though)


Spacemacs has most everything pre-packaged. I'd recommend it highly


I use it in Holy mode


Which means, without Vim bindings


spacemacs and doom-emacs are the two most popular with vim keybindings, both should run fine on linux


So shortcuts are just normal Emacs


I'd also recommend you choose Ivy instead of helm when it asks you


there is also emacs prelude, has support for clojure/cider


Spacemacs in Holy mode and with Ivy. It's not exactly VSCode like, in that some shortcuts are different like copy/paste and how selection works. But it's close. You could enable CUA mode to make it even more like VSCode


why would you choose Ivy over Helm? I've been using Spacemacs with Helm for the past 4 years and didn't have a problem with it yet. Is Ivy much faster? Or does it have a better interface?


It's much faster for me, and more responsive. And I prefer the look and feel of ivy.


Its definitely a personal preference. I know happy helmers as well

👍 4
Yosevu Kilonzo18:12:45

doom-emacs is great too!

😎 4
👍 4

Oh, also if you do try that out, use the develop branch of Spacemacs


@prakash You can definitely use Clojure without emacs - I use Cursive, and there are addons for both atom and vscode

Prakash Venkat18:12:49

iv heard that doom-emacs is less “bloated” — what does that mean?

Prakash Venkat18:12:03

@shaun-mahood thanks for the rec! iv never heard of Cursive, but ill check it out


It means it comes with less things pre-packaged


But doom is much more tied to Vim, pretty hard to use it without knowing Vim.


While I'm an Emacs lover, it is a lot to learn. If you're also learning Clojure, the advice to try Cursive (IntelliJ), Calva (VSCode) or Chlorine (Atom) is probably a good one.

Prakash Venkat19:12:17

Calva looks cool


Calva is cool. But you can't beat the debugger in CIDER (Emacs) or Cursive (Idea).


I'd be delighted if you gave Calva a spin. It definitely fits the prepackaged description. (No debugger though, but that will happen eventually.) #calva-dev is where we try to be the helpful bunch that you are used to in the Clojure community.

Sam Ferrell22:12:48

I've been using Calva on VSCode on Windows. I've struggled with almost all the other editor environments but Calva just worked. Not sure what I'd do without it

🤝 16
calva 4