Fork me on GitHub

I want to start a new clojure project to mainly for learning purposes, but even deciding how to do that is a bit overwhelming. Should I use leiningen, boot, or deps.edn? Is there a wrong answer?


If you are learning on a beginning project, I suspect picking any of those 3 will work out reasonably well for you. If and when you hit some point of the project where one of those is clearly better for your purposes than another, you will probably be better positioned at that time to see why switching might be to your advantage.


All of them can get you to the point of starting a REPL and setting up your environment (e.g. Java class path) to be able to load your code and that of libraries you may want to use.


I haven't used boot yet, but I believe the places where it vs. Leiningen will become most evident is when you have specific needs for building an application from multiple kinds of source files, e.g. not only Clojure/ClojureScript, but also Java, JavaScript, CSS, etc. If you expect to have needs like that on your beginning project, then you might want to get more people's advice than mine on your choice.


Thank you for the information. I'm going to try lein for now. I've used it before and I don't think I'll need a complicated build process.


@scott.archer tldr is that lein will get you more functionality out of the box and lets you leverage way more templates built for lein, etc. boot is considerably easier to extend and customize since your boot tasks are just straight clojure code, but you generally gotta know more about internals and there aren't plugins (or, in boot's case, pre-made tasks) for as much. Which I like because it simplifies the dev deps, but it does mean more initial work putting a project together


how can I get a full qualified function name and call it. For example, something similar to the importlib from python?


@iagwanderson You'll need to require the namespace it is in and then resolve the fully-qualified name to a var, then you can call it.


For example

user=> (def f "clojure.set/union")
user=> (namespace (symbol f))
user=> (require (symbol (namespace (symbol f))))
user=> (resolve (symbol f))
user=> (*1 #{1 2} #{2 3})
#{1 3 2}


yes, that’s exactly what I meant


Are there any benefits of having one leiningen project for the UI and one for the API which the UI communicates with?


It feels unnecessary to me, I do have it split today though.


If I were to target several plattforms it would be nice though.


Just want to give out a shoutout to since they support Clojure for their puzzles, coding battles, etc. Great learning resource, even for advanced coders. 🙂

❤️ 4
Denis G08:09:35

hackerrank supports Clojure as well. For almost all of their problems. Not only from the FP domain


If i want to call from clojure side (clj) a JavaScript code directly or trigger clojurescript code (trigger eg. add-watch at clj side > cljs trigger) then possible without websocket and rest api?


I can write fully eg atoms at clj side, call functions. I would like to solve the clj>cljs way like a websocket. I saw intern function not implemented at cljs side, any idea how to connect? So change clj atom then send to cljs part? Now, i set intervals, but not so good idea.


If somebody have any idea, i will be happy.


@sb I don’t fully understand what you want, but if you want websockets, sente is a nice library to work with


@borkdude i used sente, rest api. I solved from cljs side with macros like core.async the Vars (atoms) at clj side. I can read, write. Run clj commands from cljs part. One thing missing, if eg at clj side a websocket channel eg Slack.. when change the data I cant send to cljs just with sente.


No direct connection because in macros at cljs side i cant use the intern function


So i cant create a hook


why are you using intern?


Namespace hook


I want connect actual cljs ns to clj ns


Like cljc, with data storage


Maybe that is impossible, just i prefer use data communication without extra layer eg rest api or socket

Denis G10:09:07

is it common sense to write pre/postconditions in your function definitions? They throw exception on false, right?


@denisgrebennicov many functions throw exceptions anyway, e.g. if you call subs with out of bounds index. in that case a pre might give you some more information of what might have gone wrong anyway

Denis G10:09:30

So they do throw exceptions or it is up to you?

Andrea Imparato10:09:52

do you write these pre/postconditions with spec or what?

Denis G10:09:06

You can, but AFAIK it's other func


> If any of the conditions evaluate to false and assert is true, an assertion failure exception is thrown.

Denis G10:09:28

this is more or less the question, since AFAIK spec is kinda replacing pre-/postconditioning, right?


so you can turn it off


depends. you can even call spec from pre or post, it’s up to you

Denis G10:09:49

but is it idiomatic. AFAIUnderstood spec is pushed and is the "new" way to go instead of precondition tests Dunno if you can use spec for postconditioning though


spec doesn’t verify the :ret value unless you use clojure.spec.test. some libraries offer a workaround and do turn it on. but you can also hook it up yourself using :post


I usually write an fdef, but that’s because pre and post are not in my system, maybe I should use them more

Denis G10:09:07

this is a nice feature, IMO, but question is if this is just-nice-to-have-nobody-does-it, or nice-to-have-you-should-use-it


there is no idiomatic answer to this


I’ve never heard someone refuse a PR because he/she didn’t write enough pre/post/specs.


there are multiple ways to do it. I could have used pre now I think of a case I handled lately in a macro where I asserted that the input should meet some form, but I just used assert .


(require '[clojure.walk :refer [macroexpand-all]])
   '(defn foo [x]
      {:pre [(pos? x)]}
    (pos? x)
       (clojure.core/str "Assert failed: " (clojure.core/pr-str '(pos? x)))))))

Denis G11:09:41

nice! Thanks

Mario C.17:09:16

Does the REPL have a mind of its own?

Mario C.17:09:40

If I do this (apply hash-map (:test "example"))

Mario C.17:09:47

The result is {}


what’s the result of (:test "example") ?

Mario C.17:09:23

But that is not the case when my app is being run


dev> (:test "example")


because you have something more like '(:test "example")


there’s a difference between (:test "example"), '(:test "example") and (list :test "example")


(:test "example") as a literal in code means 'invoke :test as a function with the argument "example"'

Mario C.17:09:26

Ahh such a rookie mistake

Mario C.17:09:31

You are right!

Mario C.17:09:42

How does Clojure know when its dealing with a list or dealing with a function call?


that’s the difference between an unquoted or quoted list. the reader interprets an unquoted list as a function call

Mario C.17:09:04

Suppose I have this (defn funca [name & args] (apply funcb name args))

Mario C.17:09:27

(defn funcb [name & args] (apply hash-map args))

Mario C.17:09:59

If I println args

Mario C.17:09:13

Its just a list. No quote or unquote.


this is only important at read time


internally the object is stored as a list - it's just when you define it in the code that the quote means it is a literal object- not an s-expression

enforser17:09:33 This chapter may be useful for understanding the reader! It goes fairly in depth on how expressions are evaluated

👍 4

I would find a tutorial somewhere for writing a lisp. it will go really fast in clojure, and once you've done it, it makes this kind of thing very apparent and easy to understand

👍 4

Hey everyone, the main man himself Rich Hickey makes a lot of jokes about monads in his presentations. I am struggling to understand what they are, could anyone explain or link me to a resource where I could learn?


a monad is 1. a thing in math 2. a pattern that emerges in a lot of functional programs that has some similarities to #1 so the same name is used for both


The source of the monad jokes is that they are famously unintuitive and amateur attempts to explain them tend to make people even more confused. They aren't a concept you need for clojure. That said, category theory involves some nice patterns for thinking about computation if you want to learn some math that would inform application design.


Google for "burrito". You'll find 100 tutorials on monads 🙂


and 10,000 bad jokes about tutorials about monads


(aside from the joke and the various attributions of it, it actually explains the math)


One of my favorite jokes (no idea who said it) on monads is paraphrased "When you learn enough to understand monads, you lose the ability to explain them to people who do not yet understand them."

👍 4

I think gigasquid did quite a good job in one of her talks (at either a Clojure conference or Strange Loop)... let me see if I can find that...

Eric Ervin21:09:13

Gottfried Leibniz or GTFO


@deanjohnson03 I hope some of that helps! 🙂

Mario C.21:09:12

When you build JS from CLJS using lein cljsbuild once

Mario C.21:09:21

And then run lein ring uberjar

Mario C.21:09:37

Is the JS separate entity or embedded within the .JAR?


The goal of an uberjar is to create a single deployment artifact. You can open the uberjar in your editor or with a file manager - it's a special zip file.


the js will also be created outside the uberjar before packaging it


@noisesmith you still need an external sh script for jvm options etcc no?


right - that's outside the scope of uberjar


or can that be specified insided the jar somehow?


there is a trick for turning the jar into a #!/bin/sh script that runs java but usually you don't need that


I usually don't think of the runner script as part of the deploy, but rather part of the infrastructure deployed to - but I guess not everybody does it that way.


I would think too, makes more sense, since you also need to setup the app as a service, etc.. I guess that is why some convert the app to a distro pkg


maybe this is one of docker advantages


what's your lazy-seq question/doubt?


oh. it went away


@dpsutton heh, I'm rethinking it

Mario C.21:09:23

After opening the uberjar I notice that my site.js file isn't under the public folder anymore.

Mario C.21:09:52

After removing :clean-targets ^{:protect false} ["resources/public/js/site.js" :target-path]

Mario C.21:09:06

It now builds it and its in the proper place

Mario C.21:09:27

What gives? I thought :clean-targets only affects the outcome of a lein clean


I think uberjar implicitly cleans


one way to do this is to make the optimized cljsbuild a prep-task for uberjar


because usually you want a different kind of cljs output for prod vs. dev

Mario C.21:09:27

Any links that explains the optimized cljsbuild as a prep-task for uberjar?


:uberjar {:prep-tasks [["cljsbuild" "once" "opt"]]} or something like that


@seancorfield @hiredman @noisesmith @andy.fingerhut thank you all for your responses, I will check out all the links and info you gave me 🙂


@mario.cordova.862 you might need to manually add "clean" or any other prep tasks since that gets overwritten rather than merged (because order is important)


is deploying from github a bad idea? wink it is


not sure what you mean there, but literally thousands of companies do this every day, even from public repos.


so, no, deploying via CD setup on your repo isn’t a bad idea at all 🙂


so ["clean" "javac" ["cljsbuild" ...]]

👍 4
Mario C.22:09:53

@noisesmith Would adding :disable-implicit-clean true to my project.clj achieve the same effect?

Mario C.22:09:18

Because I am running a lein clean before running lein ring uberjar


the difference would be no longer needing to run the cljsbuild yourself (or the clean)