Fork me on GitHub
Itay Dreyfus10:09:38

Need to some advice here – started my Clojure journey as a first language a few weeks ago. I've gone through the basics and some advanced topics, but feeling a bit stuck. Basically, my main goal is to build things for the web – where should I go next? I guess my question is how to put into practice what I've learned so far. Would diving into reframe/reagent be too early? is there any middle places I should look into? I'd like to hear your thoughts!

🔥 1
Rupert (All Street)11:09:05

Client side rendered codebases (with clojurescript) require a lot more learning because the abstractions are (perhaps necessarily) leaky + you have to split logic between client and server. It's possible to build performant and interactive website that are purely server side rendered (ie. just clojure). You can also sprinkle in some HTMX or Hyperscript to make the website even more interactive (these are just HTML tags so no extra clojure library required). You could try building a server side rendered website using + Start with a "Hello World" page then build it up from there.


The book is a great resource to get into writing full-stack applications, well worth the price.

👀 1
👍 1
Itay Dreyfus12:09:59

Cool, will check it out! Have you read/used it?


Yes, but admittedly mainly the earlier editions. I do own the third edition too and from what I can tell based on some cursory reading, there seems quite a bit of changes (like using Reitit instead of Compojure API etc.). I like the way the whole stack from Ring handlers to the UI are discussed in depth with examples.

Itay Dreyfus13:09:53

Cool cool! thanks 🙂

Epidiah Ravachol13:09:12

Just popping in to thank you for the thread. I'm in a similar spot and looking for that elusive next step.

✌️ 1

A book that is a bit too outdated at this point but that was crucial to me and I still hold dear is Clojure Applied. It's an opinionated take on what it means to build Clojure applications after you get an understanding of the language but before you are confident to make decisions on how to go about building stuff and how to put what Clojure offers you together to solve problems. Wouldn't recommend as a primary target at this point (probably the above is a better lead) but it's a nice one to have within reach. :)

✌️ 1

re-frame is one good place to start, and almost a de facto standard amongst Clojurists. The downsides are that it is somewhat ornate, the upside is that it is very well documented. It also works off a secondary store a la Redux, so one gets sucked into more or less boilerplate and code juggling just to make the framework happy. That said, most of the front end community has swallowed the secondary store pill and survived. re-frame sits atop Reagent, which is nice but glitchy and provides building blocks more than a complete solution like re-frame. Both ^^^ also involve the ReactJS/Native pill. Not recommended, but again semi-standard. If ReactNative is a target, this is a great place to start: If you want to start simple, and are OK with react, try Helix, also great. I myself have a pure Web solution here which I started to document when ClojureDart turned my head. Not much doc, but it thinly wraps HTML and CSS so MDN doc works. ClojureDart (CLJD) will let you avoid React. It is brand new but quite good in its initial form. The DX might be the only weakness, but that is being worked on. Flutter/Dart are nicely stable unlike React, but nothing like the simple uniformity of HTML, and brace yourself for serious OOP. Team CLJD is making the OOP less burdensome, like any good Lisp wrapper. I am doing the same with Flutter/MX. I have a nice POC implementation, but it is undocumented until I get off social media this morning and start doing that. Belated tl;dr: as a beginner, re-frame or Helix.

👀 1
Daniel Craig16:09:20

My recommendation is to go with re-frame; it's delightful

👍 1

Since Clojure is your first language, I'd recommend taking things slower. I'd start with applications that don't need a UI (or a very minimal text-based or even REPL-based UI). When you are ready for a web UI, consider something basic like That will familiarize you with the foundational libraries used in a Clojure web app. Re-frame is great, and it addresses many real-world issues you will need to consider if you are building a production web app. But that's not where I'd start.

👍 2
🙌 1

If you can define a specific thing you want to build, more specific advice can be shared from the community E.g. do you want to build a landing page (reagent, hiccup and some CSS), or a mobile app with react native, or a full-stack app (front end + server). So figure out specifically what you want to build and go from there The web development with Clojure 3rd edition probably covers some or all of what you want, although there are many other examples and libraries Also take a look at to generate example projects that demonstrates how libraries can work together Reagent is a defacto standard in front end apps and very simple to work with, especially coupled with hiccup or Selma to manage content Re-frame builds on Reagent and is a lot more involved but a lot more features, especially for managing complex UI flows and events. Re-frame is too much simpler web UI's and you can use just parts of re-frame

✌️ 1

To start with a simple ClojureScript app, I like to use figwheel as the build tool, its simpler than shadow-cljs (although not integrated with node as shadow is) There is an article about getting started with Clojurescript and figwheel here

✌️ 1

How to traverse a folder in depth first manner and print the number of files in each folder?

Martin Půda12:09:20

Try this:

(defn traverse [file]
  (when (.isDirectory file)
    (let [files (seq (.listFiles file))]
      (println (.getAbsolutePath file) ":" (count files))
      (run! traverse files))))

(traverse (File. "."))


hi! I'm trying to solve what I think is a very simple problem, but there's something I'm missing Want to have a function that takes a number (upper bound of a range), and some predicates (evaluate a number and return true or false), and returns a list (or vector or whatever) of numbers that satisfy either predicate I have this:

(defn find-range-until-number-with-conditions [m & [predicates :as all]]
  (apply (filter some-fn all) (range 1 m)))
but when I call it, like this (find-range-until-number-with-conditions 10 [multiple-of-3 multiple-of-5]) I get this error class clojure.lang.LazySeq cannot be cast to class clojure.lang.IFn I have two questions: • What I'm just getting plain wrong? • How could I debug this in order to be more autonomous at solving this kind of beginner questions? (I get that I'm passing somewhere a seq when I should be passing some function, but that doesn't help me much at this point) BTW I want this function to solve (in a more elegant way) Project Euler #1 problem, which is easily solveable like this
(reduce +
         (some-fn #(= (mod % 3) 0) #(= (mod % 5) 0))
         (range 1 1000)))
But since I'm trying to learn, I wanted to do it the way I described above


look at the params for apply and look at the return of filter - apply expects a fn as its first arg and filter returns a lazy seq (which is not a fn)

Martin Půda13:09:37

When you swap filter and apply , it will work (`->>` is thread-last macro):

(defn find-range-until-number-with-conditions [m & predicates]
  (->> (range 1 m)
       (filter (apply some-fn predicates))))
(find-range-until-number-with-conditions 10 odd? #(> % 5))
=> (1 3 5 6 7 8 9)


that's the small thing that I was missing, I was mistaking the order thanks3