Fork me on GitHub
#beginners
<
2019-12-11
>
yiorgos07:12:15

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 %)))
    vec))
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.

yiorgos15:12:16

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

yiorgos21:12:36

Oh thank you very much!

genRaiy07:12:24

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

noisesmith17:12:52

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)

genRaiy17:12:48

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

hindol08:12:08

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. https://stackoverflow.com/a/5084289

Sam Ferrell08:12:11

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

lsenjov08:12:45

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

Cam08:12:13

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?

Cam09:12:05

@artur.aralin97 I think most people use "ring" certainly frameworks like fulcro https://github.com/ring-clojure/ring

Artur Aralin10:12:28

@cam.asoftware why ring? httpkit looks pretty simple

Cam10:12:28

@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 https://github.com/jacekschae/learn-re-frame-course-files/tree/master/increments/60-simplify-events 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: https://github.com/ReOrgpad/example-client

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.

Chris11:12:33

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

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

Chris11:12:51

It results in nil afterwards

Pavel Klavík11:12:49

since its results are not used, they are never computed

Chris11:12:57

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

Chris11:12:52

But the following still does not throw an exception:

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

Pavel Klavík11:12:54

It is different:

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

Pavel Klavík11:12:13

Or just:

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

Chris11:12:44

Cool, thanks a lot !

Adrian Smith17:12:11

I've created a beginners guide for using Cursive and Intellji in Clojure: https://adriansmith.io/clojure-setup.html I created it for a local group I'm teaching but it might be useful to others, source code is in https://github.com/slifin/adrian-smith-io if you have improvements

👍 4
beders17:12:22

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)
Have
=> (fn [] 2)
?

beders17:12:58

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

beders17:12:42

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

beders17:12:06

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
hiredman17:12:11

there are also some libraries

beders17:12:41

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?

beders18:12:21

If you like vim, it is.

beders18:12:46

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)

didibus18:12:31

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

didibus18:12:49

I use it in Holy mode

didibus18:12:01

Which means, without Vim bindings

johnj18:12:12

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

didibus18:12:22

So shortcuts are just normal Emacs

didibus18:12:43

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

johnj18:12:46

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

didibus18:12:13

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

sebastian11:12:36

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?

didibus00:12:25

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

didibus00:12:43

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

👍 4
Yosevu Kilonzo18:12:45

doom-emacs is great too!

😎 4
👍 4
didibus18:12:53

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

shaun-mahood18:12:23

@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

didibus18:12:02

It means it comes with less things pre-packaged

didibus18:12:40

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

didibus18:12:22

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

hindol19:12:05

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

pez20:12:46

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