/r/Clojure

Photograph via snooOG

Clojure is a dynamic, general-purpose programming language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming.

Finding information about Clojure

API Reference

Clojure Guides

Practice Problems

Interactive Problems

Clojure Videos

Misc Resources

The Clojure Community

Clojure Books

Tools & Libraries

Clojure Editors

Web Platforms

Clojure Jobs

/r/Clojure

32,178 Subscribers

16

New Clojurians: Ask Anything - May 13, 2024

Please ask anything and we'll be able to help one another out.

Questions from all levels of experience are welcome, with new users highly encouraged to ask.

Ground Rules:

  • Top level replies should only be questions. Feel free to post as many questions as you'd like and split multiple questions into their own post threads.
  • No toxicity. It can be very difficult to reveal a lack of understanding in programming circles. Never disparage one's choices and do not posture about FP vs. whatever.

If you prefer IRC check out #clojure on libera. If you prefer Slack check out http://clojurians.net

If you didn't get an answer last time, or you'd like more info, feel free to ask again.

10 Comments
2024/05/13
10:01 UTC

5

One question regarding for and doseq macro in case of recursive function

I have a map like

{"/"

{"b.txt" 14848514,

"c.dat" 8504156,

"a" {"f" 29116, "g" 2557, "h.lst" 62596, "e" {"i" 584}},

"d" {"j" 4060174, "d.log" 8033020, "d.ext" 5626152, "k" 7214296}}}

I ran one function that uses doseq macro

(defn c-seq

[inp]

(doseq [[key value] inp

:when (map? value)]

(do (c-seq value)

(println [key (get-size-of-directory value)]))))

and then I ran other function that uses for macro

(defn c

[inp]

(for [[key value] inp

:when (map? value)]

(do (c value)

[key (get-size-of-directory value)])))

now since the doseq cannot return anything I printed the response

the response was

[e 584]

; [a 94853]

; [d 24933642]

; [/ 48381165]

but for the function utilising the for macro returned value is only

(["/" 48381165])

I am not sure as to why is recursion not happening in the function using for can anyone please help me with this?

14 Comments
2024/05/12
21:12 UTC

9

How do I create dialogs in cljfx?

I have started making a desktop app with cljfx for two days now, and it's been a wonderful experience so far!

But I just can't figure out how to create alerts and dialogs in cljfx. The only resource I have found is this example https://github.com/cljfx/cljfx/blob/master/examples/e17_dialogs.clj, but it is stateful and I want to launch a dialog anywhere from the click of a button which doesn't depend on the app's state.

4 Comments
2024/05/11
04:26 UTC

44

What are the good things in Clojure between 2018 and now?

I'm learning Clojure and loving it so far

As is usually the case when I'm learning something, I turn to well-received books first before diving into other resources

So far I've read "Clojure for the Brave and True" and "Getting Clojure" - now I'm reading "The Joy of Clojure"

The most recent of those was Getting Clojure, from 2018, and I believe in these six years things might've changed - I know that a few things have been introduced and/or started to be more widely used, and some things are not widely used anymore

What are those things?

I've read a comment somewhere that e.g. Refs and Agents are not super common anymore. Also read that transducers are very common

33 Comments
2024/05/09
22:08 UTC

7

People who have used vue, svelte how does it compare to reagent/reframe at this moment

I wanted to learn how good reagent/reframe is compared to vue or svelte these days. Also is the Cljs community growing?

7 Comments
2024/05/09
15:52 UTC

5

Is htmx+alpine.js powerful enough to take on Clojurescript

Ik cljs has its learning curve but is this worth the power it brings over something simple like htmx+alpine. Additional question, will Cljs work as nicely if I'm using Golang in the backend? (New to web dev)

10 Comments
2024/05/08
21:22 UTC

4

Searching for a Data Model with good static analysis tools

I love the simplicity of 'maps-as-data', but they make refactoring hard.

If I want to change the name of a record field, how do I find all references, and ensure they get updated?

In a lot of ways I prefer the emacs-lisp approach of prefix-naming all the structure-accessors, so that when I make changes, the things I need to update are searchable. Malli works well as schema validation, but for me it doesn't solve the problem of providing safe refactors.

Right now I use emacs + clj-kondo (with cider+lsp-mode), but refactoring is still a challenge. I've tried core.typed, but as others have pointed out it feels more like a research project and is tricky to get up and running in production.

Any suggestions on how to fix this? Are there good macro libraries with a more rigid data model? Ideally (best case-scenario) looking for libraries with good tooling built around them.

9 Comments
2024/05/08
15:09 UTC

15

On installing Clojure

Around 5 years ago I installed clojure by first installing leiningen, but I know build tools and dependency management preference have changed over the years, so I wonder: what are the options I have these days to install clojure in a development environment. I'm running Debian 12 Bookworm, and I know the official page recommends this: https://clojure.org/guides/install_clojure

EDIT: spelling

14 Comments
2024/05/06
13:59 UTC

10

New Clojurians: Ask Anything - May 06, 2024

Please ask anything and we'll be able to help one another out.

Questions from all levels of experience are welcome, with new users highly encouraged to ask.

Ground Rules:

  • Top level replies should only be questions. Feel free to post as many questions as you'd like and split multiple questions into their own post threads.
  • No toxicity. It can be very difficult to reveal a lack of understanding in programming circles. Never disparage one's choices and do not posture about FP vs. whatever.

If you prefer IRC check out #clojure on libera. If you prefer Slack check out http://clojurians.net

If you didn't get an answer last time, or you'd like more info, feel free to ask again.

2 Comments
2024/05/06
10:01 UTC

15

What are your favorite async patterns?

I find myself using core.async and sometimes manifold more than ever. It's silly, I always manage to get things done, but it usually takes a good amount of trial and error to find the right way to do something.

What are the most common patterns you encounter when writing async code in Clojure?

18 Comments
2024/05/04
23:39 UTC

47

Making mobile games with Clojure + React Native

I recently had the opportunity to revive an old project

that was basically a POC of using ClojureScript + React Native to make 2D mobile games.

Thought someone might find it interesting, and maybe get inspired to build something!

https://github.com/divs1210/cljs-expo-game

Screenshot:

https://preview.redd.it/ec78yvscbdyc1.png?width=1468&format=png&auto=webp&s=11f42d622c75e8143a6a1a320d3a7cad89e910d3

0 Comments
2024/05/04
08:12 UTC

3

Best approach for writing a Clojure systemtray applet?

Tips on the best way to go about writing a systray applet (systemtray app, or whatever it should be called)?

I've found:

Much of this seems rather old though (the HN Tray app doesn't work; it points to a dead URL and pointing it instead at different HN apis doesn't work either - I assume the json parsing would need redoing), and so I wondered if I should be looking at anything else (or if it's just that no-one writes systray apps anymore).

7 Comments
2024/05/04
01:32 UTC

17

London Clojurians Talk: From data to insights: Clojure for data deep dive (by Kira McLean)

0 Comments
2024/05/01
13:06 UTC

16

Snippet code review, is it too clever? (i.e. not too clear)

https://preview.redd.it/tnpvwtsj9sxc1.png?width=651&format=png&auto=webp&s=4bd7fbe04de64dcd7a5b403b305af88ce7060043

What I am doing here is to render some DIVs that encapsulate an "action", on one client (the active one), the actions must be clickable on the others I just want to show what the other players can do but the buttons must be disabled.

Is there a better way to express this? I have the feeling that I am abusing cond-> and that a better, more readable approach, must exists...

19 Comments
2024/05/01
09:29 UTC

12

Who is hiring? April 30, 2024

Please include any restrictions (remote/on-site, geographical, workpermit, citizenship) that may apply.

3 Comments
2024/04/30
22:00 UTC

5

Oauth2 provider solutions?

Heya! I'm exploring my options for setting up a clojure server that can also serve as an oauth provider.

In my mind, building your own oauth2 provider fully from scratch is an herculean effort (or is it?), and so using a library would be better.

What I could find is cerber but it seems to not have been updated in 5 years. I'm wondering if there are any other alternatives that I've missed?

5 Comments
2024/04/30
19:12 UTC

49

ThePrimeagen and Uncle Bob talking about Clojure

46 Comments
2024/04/30
06:02 UTC

8

Trying to get the Nuklear GUI library (part of LWJGL) to work with Clojure

I would like to add some GUI elements to an OpenGL application. I wonder if anybody got Nuklear working with Clojure. I only managed to get to a point where it calls a progress bar (testing this first because it doesn't seem to need font setup) and nk_progress actually returns true without crashing. However the window stays black. Any help would be appreciated.

deps.edn:

{:deps {org.clojure/clojure {:mvn/version "1.11.3"}
        org.lwjgl/lwjgl {:mvn/version "3.3.3"}
        org.lwjgl/lwjgl$natives-linux {:mvn/version "3.3.3"}
        org.lwjgl/lwjgl-opengl {:mvn/version "3.3.3"}
        org.lwjgl/lwjgl-opengl$natives-linux {:mvn/version "3.3.3"}
        org.lwjgl/lwjgl-nuklear {:mvn/version "3.3.3"}
        org.lwjgl/lwjgl-nuklear$natives-linux {:mvn/version "3.3.3"}
        org.lwjgl/lwjgl-glfw {:mvn/version "3.3.3"}
        org.lwjgl/lwjgl-glfw$natives-linux {:mvn/version "3.3.3"}}
 :paths ["."]}

nuklear_example.clj:

(ns nuklear-example
    (:import [org.lwjgl.glfw GLFW]
             [org.lwjgl.opengl GL]
             [org.lwjgl.nuklear Nuklear NkContext NkRect NkUserFont]
             [org.lwjgl BufferUtils PointerBuffer]
             [org.lwjgl.system MemoryUtil MemoryStack]))

(GLFW/glfwInit)

(defn make-byte-buffer
  [data]
  (doto (BufferUtils/createByteBuffer (count data))
    (.put ^bytes data)
    (.flip)))

(def window (GLFW/glfwCreateWindow 640 480 "Nuklear Example" 0 0))

(GLFW/glfwMakeContextCurrent window)
(GLFW/glfwShowWindow window)
(GL/createCapabilities)
; (GLFW/glfwSwapInterval 1)

(def context (NkContext/create))

(def stack (MemoryStack/stackPush))
(def cur (.mallocLong stack 1))
(.put cur 0 50)
(println (.get cur 0))
(def rect (NkRect/malloc stack))
(def font (NkUserFont/create))

(def memory (byte-array 1000000))

(def buffer (make-byte-buffer memory))

(Nuklear/nk_init_fixed context buffer font)

(while (not (GLFW/glfwWindowShouldClose window))
       (GLFW/glfwPollEvents)
       (when (Nuklear/nk_begin context "Nuklear Example" (Nuklear/nk_rect 0 0 640 480 rect) 0)
          (Nuklear/nk_layout_row_dynamic context 128 1)
          (let [p (PointerBuffer/allocateDirect 1)]
            (.put p (MemoryUtil/memAddress cur))
            (.flip p)
            (println (Nuklear/nk_progress context p 100 true))
            (Nuklear/nk_end context)
            (GLFW/glfwSwapBuffers window))))

(Nuklear/nk_free context)

(GLFW/glfwTerminate)

(System/exit 0)

I put the code in a Github repository as well.

8 Comments
2024/04/29
21:25 UTC

8

New Clojurians: Ask Anything - April 29, 2024

Please ask anything and we'll be able to help one another out.

Questions from all levels of experience are welcome, with new users highly encouraged to ask.

Ground Rules:

  • Top level replies should only be questions. Feel free to post as many questions as you'd like and split multiple questions into their own post threads.
  • No toxicity. It can be very difficult to reveal a lack of understanding in programming circles. Never disparage one's choices and do not posture about FP vs. whatever.

If you prefer IRC check out #clojure on libera. If you prefer Slack check out http://clojurians.net

If you didn't get an answer last time, or you'd like more info, feel free to ask again.

30 Comments
2024/04/29
10:01 UTC

47

The Anatomy of a HTTP server

Greetings fellow Clojurians,

The upside of looking for work is that there is time left to inquire about things and be creative. Over the course of a week, I dedicated my mornings - when I'm at peak mental clarity - to creating content for my blog. The latest entry is an in-depth post on the topic of HTTP and web application development.

We start with a minimalist web server that soon enough honors the semantics of HTTP/1.1 GET requests. Then, we write a Ring adapter for our server, decoupling the nitty-gritty from application logic.

This whirlwind tour sheds light on the design of web frameworks that emerged in all language communities (Servlets, WSGI or Rack), reflecting the need to standardize around a portable interface abstracting HTTP.

At the same time, I went to great length documenting the experience of living and breathing at the REPL. Throughout the post, I explain each decision point and experimentation that ultimately led me to the final design. I know beginners often struggle with REPL-oriented development and I hope this will be helpful in a Show, don’t tell manner.

For advanced users, feel free to skip the introductory sections and jump to the final code. I welcome contributions from the community that keep the spirit of the exercise: no external dependencies, single namespace, brevity and simplicity of code.

You will find the The Anatomy of a HTTP server on my blog dedicated to Lisp programming.

As always, feedback is most welcome! Thank you!

4 Comments
2024/04/28
07:06 UTC

Back To Top