Fork me on GitHub
#beginners
<
2020-10-05
>
Chris K06:10:49

trying to use compojure, hiccup, and cljs together but while I was able to make hiccup and clojure work together, I couldn't figure out how clojurescript would work with hiccup... I don't even know very much of how clojurescript works and can anyone forward me to some resource?

yogidevbear07:10:05

There's also #clojurescript which might be a good place to ask more specific questions related to ClojureScript

Jim Newton07:10:47

does anyone know of a clojure system named genus ? I need a clever and somewhat abstract name for a package which I intend to eventually publish. I dont want to take a name that already means something to someone. Naming is hard.

Chris K07:10:07

maybe u can search it on clojure toolbox?

1
Chris K07:10:32

@jimka.issy and no I couldn't find one named genus

Jim Newton07:10:36

I did a google search for clojure and genus and didn't find anything. I didn't specifically try clojure toolbox.

Jim Newton07:10:03

my other option is compositus not sure yet.

delaguardo08:10:45

clojure libraries often follow naming convention taken from java (e.g. org.clojure/clojure) this is the way how to make your library name unique

delaguardo08:10:19

most recent version of clojure cli even start warn developers about using unqualified lib names DEPRECATED: Libs must be qualified, change clj-http => clj-http/clj-http

andy.fingerhut08:10:29

I think if people want to be squeaky clean, and/or if you ask them how in Java and Clojure land to keep library/artifact names unique, they would agree that using reverse DNS names as a group, and a separate name as an artifact, is a good idea. There certainly are a heck of a lot of Clojure libraries that haven't bothered with the reverse DNS names, of course. I suspect that has more to do with expediency and/or lack of awareness than anyone advocating for the current state.

Jim Newton08:10:23

i suppose there are really two questions hidden in my question. 1) How do I conform to the correct semantics of naming so as to avoid name clashes? and 2) how to choose a name which is colloquially distinct? as per #2, i could certainly name my library spec with the appropriate reverse dns name. However, that would not be culturally compatible with clojure social community.

Jim Newton08:10:43

A part of DNS naming which I don't understand is where does the DNS path need to come from. If I use, for example, the name of my research institute, what should have if I change employer in the future? Would I need to fork and rename? Or do I really need to create a personal DNS independent from my location, employer etc?

Jim Newton08:10:26

a personal DNS is a bit hard to justify, being that I don't even have anything at the moment to publish

andy.fingerhut08:10:45

Yeah, spec would be a poor choice, even with the reverse DNS name as a group. Google searches for "clojure genus", or whatever project name you are interested in using, is certainly one good filter, as well as asking here if you are worried about it. Very rarely, things fall through the cracks, and someone renames a project as a result. At least, I've heard of that happening for libraries in other languages.

andy.fingerhut08:10:43

Personal DNS names are about $10/year, if I recall correctly.

andy.fingerhut08:10:55

At least, the uncontested ones are.

delaguardo08:10:06

you do not need personal DNS to name your library

andy.fingerhut08:10:52

Agreed that it isn't a requirement, but neither is it a requirement to make a group id that is different than the name of the library.

delaguardo08:10:53

for instance I can use me.delaguardo as a qualifier for my libs without actually paying for http://delaguardo.me

2
Jim Newton07:10:18

that's also unfound in clojure toolbox

Chris K07:10:52

I don't no too much but I think u can change the name afterwards? not sure tho depends on how you develop it but if it is not on google or clojure-toolbox, then I think you should be fine

Chris K07:10:52

For compojure, I am trying to use jetty webserver as I've seen in practicalli's tutorial, and when I use the default compojure lein template, it uses ring server. I want to change it to jetty, can someone help me? like a code snippet would be greatly appreciated. (I tried code myself but none of them really worked)..

practicalli_john09:10:40

It’s for a Leiningen project, but apart from dependencies it works the same for Clojure CLI tools. Feel free to @ mention me or use the #practicalli channel for help

Chris K10:10:41

thanks a lot 😄

practicalli_john10:10:45

The compojure template does hide some details, I thought it did use jetty by default but the details are probably in one of the libraries its using.

practicalli_john11:10:18

I notice that when running lein ring uberjar to packing up a project created with lein new compojure todo-app it downloads the ring/ring-jetty-adapter library, so it seems that project its already using jetty, it just hides that fact under a few abstractions.

Chris K11:10:12

so I should basically be fine with the default condition the template is in?

practicalli_john12:10:04

Fine in that it is using jetty and you are happy using the lein ring xxx commands to run the server externally. I think the compojure template included wrap-reload as part of the wrap-defaults, so when running the server with lein ring server it should automatically reload any code changes that are called from the defroutes function and in the defroutes funciton itself. And if you want to package up the application, then ensure lein ring uberjar is used to generate the jar file, otherwise the jar file will not include the code that lein ring server automatically injects. I moved away from lein ring plugin a while ago, but its convenient for getting started.

Maurice Fingher08:10:40

I just installed lein, Clojure and Cursive on Windows 10 and was able to launch REPL. All right but what I'm looking for is Clojurescript with figwheel-main.

Maurice Fingher08:10:03

I tried using the template but could not install cli and lein doesn't understand "lein fig:build". Pretty sure that somebody had thesame problem, Am I right? Any clue ? Thanks.

practicalli_john09:10:29

This is a simple project that uses Leiningen and figwheel-main. The readme explains how the project was created and how to use it https://github.com/practicalli/practicalli-landing-page

Shriyans09:10:52

Hi ! how can i optimize my clojure code for math operations or basically find out where type information can help ?

andy.fingerhut09:10:50

One good resource for Clojure performance in general is http://clojure-goes-fast.com/

andy.fingerhut09:10:48

If you are interested in arithmetic on Clojure on the JVM and want to use Java primitive types long and/or double wherever possible, this library might be helpful: https://github.com/ztellman/primitive-math

Shriyans10:10:49

@U0CMVHBL2 ahh primitive math looks great. but this won’t work with clojurescript right ? i forgot mentioning a key detail, this code is intended to work with both clojure and clojurescript basically this is the library https://github.com/shrynx/circle-packing i intended to use it with quil (processing wrapper) on both clj and cljs, but the same algorithm when written in javascript is quite faster. is there a way to optimise for both clj and cljs @U04V15CAJ i’ll go through the link, thank you. (set! warn-on-reflection true)`` looks pretty useful and probably what i need

borkdude10:10:51

@U7W7M34UQ Also:

(set! *unchecked-math* :warn-on-boxed) 

andy.fingerhut10:10:06

I know almost nothing about trying to optimize ClojureScript or JavaScript. You could try asking in the #clojurescript channel.

littleli10:10:42

I have a piece of code represented by class, not under my control and I want to give it a deref capability, similar to how Futures are treated in core. It seems that the only way to do it is write an adapter. There is no protocol to give it such capability adhoc. Is it a correct observation?

alexmiller12:10:21

Correct, it needs to implement IDeref

👍 1
Rameez11:10:44

Hey folks! Need a little bit of beginner help with regads to sorting. I have the following structure {[2019 10] 21, [2020 9] 17} where format of each item is "[year month] amount". How best to sort this structure such that I have the latest "month" last?

Rameez11:10:03

BTW. This how I'm forming this if it helps.

Rameez11:10:13

(->> data (map #(assoc % :grouping [(:year %) (:month %)]))
       (group-by :grouping)
       (map (fn [[g t]]
              [g (->> t (map :amount) (reduce +))]))
       (into {})))

Rameez11:10:53

I'm currently looking at sorted-map for this. Am I on the right track?

vlaaad11:10:09

(group-by (juxt :year :month)) is shorter 🙂

vlaaad11:10:31

e.g. no need for the first map

Rameez11:10:08

Thanks @U47G49KHQ. Does that help with ensuring the order in the end?

vlaaad11:10:20

what do you mean having latest month last?

vlaaad11:10:27

sort by month, then by year?

vlaaad11:10:01

you can use (into (sorted-map)) instead of (into {}) to sort by keys

Rameez11:10:08

By year then month. Sorry should have been more clear 🙂

vlaaad11:10:24

so just (into (sorted-map)) then?

Rameez11:10:01

Cool tried that earlier. Didn't seem to work unfortunatly

vlaaad11:10:15

user=> (->> data 
            (group-by (juxt :year :month)) 
            (map (juxt key #(->> % val (map :amount) (reduce +)))) 
            (into (sorted-map)))
{[2019 10] 21, [2020 9] 17}

Rameez11:10:39

hmm let me try again.

Rameez16:10:50

Ah that worked! Thanks @U47G49KHQ :) appreciate the assistance.

vlaaad16:10:27

No problem :)

oly13:10:28

anyone know how to run codox from deps.edn clojure command line ?

Max Rothman16:10:20

What’s the idiomatic way to map a function into a nested collection? For example, in Haskell I’d do:

=> (map . map) (+ 1) [[1, 2], [3, 4]]
[[2, 3], [4, 5]]
The best I could come up with in clojure was:
user=> (((comp #(partial map %) #(partial map %)) inc) [[1 2][3 4]])
but that seems pretty ugly

schmee16:10:13

I reach for Specter for these kind of things: (transform [ALL ALL] your-fn your-coll)

alexmiller17:10:26

clojure.walk/post-replace is probably the best core option

Max Rothman17:10:22

How would you use that to apply a function to every element? AFAICT postwalk-replace only does value replacements

alexmiller17:10:31

it walks every element

alexmiller17:10:40

that's the whole point

alexmiller17:10:13

oh, you might need postwalk if you're applying a function, sorry if that's what you were asking

alexmiller17:10:15

like (clojure.walk/postwalk #(if (number? %) (inc %) %) the-data)

Max Rothman18:10:22

aha, that does it

Malik Kennedy19:10:22

http://java.io.FileNotFoundException: I thought I knew how to load project-local .clj namespaces, but the errors tell me I'm missing something. https://pastebin.com/raw/s8ZLQEaM (It was ~40 lines, IDK etiqutte about posting long posts vs pastebin)

dpsutton20:10:00

what are you doing when hitting this error?

Malik Kennedy20:10:36

lein ring server

Malik Kennedy20:10:39

Weird part to me is in REPL evaluating (auth.views.login/login-view) gives me the map I want. But running as server it claims to not know where it is, either in a ns :require or as a fully qualified ns/fn

dpsutton20:10:17

what's the entry of :source-paths in your project.clj?

seancorfield20:10:43

(GET "/login" []
	(auth.views.login/login))  
It is not good practice to reference namespaces without requiring them. Depending on the path through the code, you may end up trying to use that symbol reference before the ns it lives in has been loaded.

seancorfield20:10:16

(I didn't see auth.views.login in the :require in auth.token -- although you did omit some of that from the paste)

dpsutton20:10:18

your error message complained about looking for views/login.clj. How are you requiring that ns?

Malik Kennedy20:10:56

Required in ns declaration like so

(:require
   [auth.views.login :as login] ...) 
when I eval (ns ...) in repl I get
1. Unhandled java.io.FileNotFoundException
   Could not locate auth/views/login__init.class, auth/views/login.clj
   or auth/views/login.cljc on classpath.
whilst lein ring server errors out and points to line containing (auth.views.login/login) or (login/login)`
Syntax error (FileNotFoundException) compiling at (/tmp/form-init7302222187445651419.clj:1:73).
Could not locate auth/token__init.class, auth/token.clj or auth/token.cljc on classpath.

dpsutton20:10:52

avoid lein ringer server for now and just start a repl. then at the repl try (require '[auth.views.login :as login]) this would keep it as simple as possible. if that works you should be good to go. if not, then lein ring server will be just more machinery obscuring what is going on

dpsutton20:10:38

and can you tell me how you're starting the repl and from what directory?

Malik Kennedy20:10:33

$PROJECT_DIR/src/auth is where I'm running lein ring server and I start the repl from inside emacs daeomon with cider-jack-in

dpsutton20:10:19

run it from the root directory

dpsutton20:10:51

when using cider-jack-in did you try (at a fresh repl) (require '[auth.views.login :as login])?

Malik Kennedy20:10:16

Yes.

(require '[auth.views.login :as login])            
1. Unhandled java.io.FileNotFoundException
   Could not locate auth/views/login__init.class, auth/views/login.clj
   or auth/views/login.cljc on classpath.

Malik Kennedy20:10:31

Run at $PROJECT_DIR has no difference afaict

Could not locate auth/token__init.class, auth/token.clj or auth/token.cljc on classpath.

Full report at:
/tmp/clojure-5505124517661228879.edn
Subprocess failed (exit code: 1)

dpsutton20:10:19

the the login.clj file is located at PROJECT_ROOT/src/auth/views/login.clj?