Fork me on GitHub
#beginners
<
2023-01-10
>
Empyreans09:01:31

Lets say I have ClojureScript data for example a Map. Is there an idiomatic way to transfer that data to a Clojure project / repl where I have access to some libraries not available in ClojureScript? So I need to use ClojureScript for getting the data, and I want to use Clojure for transforming that data. How would I go about this?

dumrat09:01:28

copy to clipboard edn output and then read from clojure?

practicalli-johnny10:01:10

To transfer when running the applications, add an API to the Clojure application (using reitit or compojure) and call the API from the ClojureScript application

Empyreans10:01:47

perfect, thank you!

Stephan Renatus19:01:23

🤯 I just can’t figure out which setting in vscode is giving me the “bad indentation” highlighting here 👇 By any chance, does someone know the knob to turn? I’m not using many extensions…

2
pez19:01:48

Assuming you are using #calva, check http://calva.io/formatting out.

Stephan Renatus19:01:43

I’m using calva, and it does work, too; but since I know these indentation warnings from other languages, I thought it was generic VSCode thing that’s interfering. but I’ll have another look at the docs, thank you!

Stephan Renatus19:01:49

😅 this is really annoying

Stephan Renatus19:01:08

yes!!! thank you so much. the one I suspected the least tbh. that’s on me. Thanks again.

skylize19:01:48

I set the coloring for that extension to be transparent shades of grey or shades of my theme's main background color, increasing in darkness/opacity with further indents. And disable the warning color for Clojure.

Stephan Renatus19:01:24

thanks, disabled that for clojure, too. that’s the best of both worlds. 🥳

✌️ 2
metapredicate19:01:01

Is there a https://hoogle.haskell.org/ analogue for Clojure, where I can look up function definitions?

Stephan Renatus19:01:53

💭 How does that work without types? Don’t all n-ary functions look the same, except for function/arg names?

metapredicate19:01:52

Hoogle allows you to search via type signatures and find functions that fit those types sure. I meant in a more general sense is there a preferred site to simplify looking up clojure functions and their definitions.

practicalli-johnny19:01:03

http://clojuredocs.org has a look up for Clojure core, includes a link to the source code of each function

Alex Miller (Clojure team)19:01:05

^^ give it arg /returns, leverages specs to find the function

phronmophobic19:01:12

@U03EK3XB4S3, I'm curious what type of search you're trying to do. I started working on a similar thing for clojure, but couldn't figure out what kind of searches might be useful.

metapredicate19:01:26

thanks for the above suggestions. I think you guys are over-thinking what I was looking for. I was looking for a more centralisalised documentation wiki for major clojure functions. Nothing involving any pattern matching magic! 🙂 I also found which just redirects to other pages, but is useful: https://www.clojure-toolbox.com/

phronmophobic19:01:33

If you're trying to find relevant libraries, I recently released https://phronmophobic.github.io/dewey/search.html and have found it useful. There's also https://cljdoc.org/ #C8V0BQ0M6

🙌 2
🔖 2
dpsutton20:01:05

Perhaps not exactly what you are looking for, but I think one super power of Clojure is the queryable runtime: apropos, find-doc, doc, and source among others

☝️ 6
2
Danilo Oliveira20:01:04

Noob question. In reagent leiningen template, some code like this is written: (defn page-for [route] (case route :index #'home-page :about #'about-page :items #'items-page :item #'item-page)) Why is the #' used? I removed this symbol and the page still works. Looks a bit Common Lisp/Lisp 2 using a special notation to refer to functions...

pavlosmelissinos21:01:19

Make a visible change to the implementation of home-page (or any of the others), reevaluate it and reload the page. Do you see the change with the symbol? How about without it? #' is the var quote: https://clojure.org/reference/reader#_dispatch The last example on clojuredocs showcases its usefulness: https://clojuredocs.org/clojure.core/var

Danilo Oliveira21:01:26

still works, I'm using shadow-cljs

Fredrik Andersson21:01:40

Hi, I'm going through the lacinia tutorial and they reference dev-resources/user.clj https://lacinia.readthedocs.io/en/stable/tutorial/init-schema.html . But I don't understand how that works. And I cant find any references on google. Does anybody know what they mean?

dpsutton21:01:59

> We can add a bit of scaffolding to the user namespace, specific to our needs in this project. When you launch a REPL, it always starts in this namespace.

Fredrik Andersson21:01:18

yes, but what does that mean?

dpsutton21:01:09

When you start a REPL it has to always be in a namespace. By default is the namespace user

dpsutton21:01:30

Clojure at runtime looks for user.clj on the classpath and will use this to define the namespace if found

Fredrik Andersson21:01:49

okay, so I can put the user.clj in the src/ folder?

dpsutton21:01:11

you could, but then it would always be present. It’s preferrable to put it somewhere so it is conditionally on the classpath

dpsutton21:01:37

that’s why they are using dev-resources. When doing dev this will be on the classpath but this (presumably) won’t be added to any artifacts you make

dpsutton21:01:57

> We can define the user namespace in the dev-resources folder; this ensures that it is not included with the rest of our application when we eventually package and deploy the application.

Fredrik Andersson21:01:49

allright, so i would add dev-resources to sources in project file?

Alex Miller (Clojure team)21:01:30

just fyi, "By default is the namespace user " is not necessarily true - this is up to the repl implementation and there are repls that do other things. Loading user.clj is special in the Clojure runtime and independent from whatever choice is made in how the repl starts (and whether there even is a repl)

Fredrik Andersson21:01:53

okay, im using vanilla lein

dpsutton21:01:37

(thanks for the clarification. i get a bit handwavy on how all of this works)

Fredrik Andersson21:01:20

thanks, now I understand

dpsutton21:01:41

for lein you’ll want to use the profiles and add it in a profile that won’t be in effect when building your artifacts

Michał Frątczak22:01:47

Why doesn't it loop indefinitely? Because clojure is lazy?

(loop [i 0]  
  (when (< i 5)    
    (println i)    
    (recur (inc i)); loop i will take this value
))

dpsutton23:01:08

the only way it continues loop is when the recur form is invoked. And that only happens when (< i 5)

dpsutton23:01:40

Each time you recur you increment i and it will eventually be greater than 5. So the when form returns nil rather than evaluating the println and recur

Michał Frątczak23:01:30

ahh yes! that when closing ) is very important 🙂

dpsutton23:01:32

yeah if you were to barf the recur out of the when you would get 5 prints to your output and a very warm computer 🙂

ghadi00:01:25

Clojure is not lazy, btw. It is strictly evaluated.

ghadi00:01:57

It has lazy sequences in the core library , but the language itself is strict

kennytilton23:01:55

"ahh yes! that when closing ) is very important 🙂" Slippery little devils, those (s and )s. I ignore them, look at the indentation. Mind you. I hit the "re-indent" key chord mode than I write code.

👍 4