Fork me on GitHub

How do you organize your projects? src, test, dev, resources, dev-resources as top-level dirs? When you run your unit tests do you allow them to see code in dev? How should one use dev? Currently I’m working with some guys who are liberally including dev and dev-resources files in tests. I was under the impression what happened in dev was more of a playground rather than a place for test utilities (code to help run tests) to live. Thoughts?


discover your own conventions. see if you regret it later. better to just think of classpath roots. your test alias will include whatever classpath roots it needs for its purposes. does stand to reason why is dev-resources and test separate. but no harm in any of this stuff if you just realize that aliases just conditionally add folders to the classpath. then the names are basically irrelevant


Hi I have what may be a noob kit-clj question. I'm trying to implement the guestbook with hiccup/htmx instead of Selmer and I keep getting an error that I'm just not sure about. In my system.edn I have

:reitit.routes/ui {:base-path "",
                    :query-fn #ig/ref :db.sql/query-fn
                    :env #ig/ref :system/env}
(which is properly configured afaik) and my web/routes/ui.clj file has these lines so I thought it would work.
(derive :reitit.routes/ui :reitit/routes)

(defmethod ig/init-key :reitit.routes/ui
  [_ {:keys [base-path]
      :or   {base-path ""}
      :as   opts}]
  [base-path (route-data opts) (ui-routes opts)])
I keep getting "Unable to resolve symbol query-fn in this context" when I call query-fn in we/routes/ui.clj. Any help is appreciated!


maybe asking in #C02T4GSBSJ1 helps more too? 🙂


can you share more code?


I've gone ahead and placed the project into a public repo here


oh no you didnt have to share the whole thing. see for correct usage of query-fn


so you just need to add one let block or something to the same effect


@UP82LQR9N Thank you so much! It works now :)


Hello teachers of Clojure. I have a question as someone who already wrote some code even though I don't feel compelled to call myself proficient dev in Clojure. The question is what's a recommended way to learn writing macros in Clojure? I feel like resources on how to start writing macros, understand them and avoid pitfalls are pretty sparse. That said, macros is an unconquered bastion currently at my Clojure journey and I want to overcome this.

👍 1
Lennart Buit10:11:27

As a high level overview


Also see informative thread from yesterday about best practices, particularly when (not) to use macros.

👍 3

First rule of Macro Club.... Don't write macro's. (especially if you haven't spent days/weeks of hammock time considering this choice) I have been working commercially with Clojure since 2017 and have yet to feel the need to write a macro. If I end my career never putting a Clojure Macro I have written into production I will be very pleased. I feel writing macros really should be one of last things to learn (unless there is an overwhelmingly value in using a macro - it's almost always better to write a function).

👍 2

When learning macros in Lisp I got a great deal out of On Lisp by Peter Seibel, which has a which could be helpful to you. While macros are often used as utility (`with-open`,`doto` etc) and control flow, I think one reason they're not used to extend syntax as often as they do in Common Lisp, is that Clojure has data literals, so instead of writing macro manipulating syntax one writes functions manipulating data. Compare Hiccup with, for example.

👍 1

@U05254DQM I agree with the spirit of this wholeheartedly. However it's also fair to say that some usage of macros can actually capture, and enforce, certain aspects mostly control flow pretty well.


@UBLU3FQRZ I would be very interested to see examples of macros that provide value (outside of Clojure core of course), especially if they are accompanied by reasons why they cant be done as effectively with functions.


Hi! I am using Calva and VSC for coding in Clojure and my language server seems to be unable to run. As you can see, the icon for the clojure language server is perpetually spinning. I tried reproducing the error with a different project, but I get this issue only for one specific repository. I tried deleting and recloning the repo but the issue persist. Any ideas on what could be the reason for this problem? Thanks in advance!


Very interesting... Do you have a clue, @UKFSJSM38?


That's intended! clojure-lsp won't start if it cannot get a valid classpath, from the error message it's not finding clojure , probably not available on your VSCode 's PATH


How can I make it find the class path?


good question 😅 don't know that much of vscode


Why would it work with other projects, but not this one? Anyway, if you have clojure in the PATH when using a terminal, you can start code from there and it will make VS Code have the same PATH.


other may be lein projects and lein vscode is finding for example


but yeah, odd if other are clojure projects as well


We'll find out, I hope. 😃


Weirdest thing happened.. It just suddenly started working


That's cool, but also means we might not find out. 😃


OK no I restarted and Its not working again xD


Ar you on a Mac?


Monterey 12.6.1


Tried starting code from a terminal?


You might need to run the command Install command line code or whatever it is named in VS Code first.


But you want that. It is a power command!


Are you sure you didn't press Ignore button on that classpath warning? if so, you may find some features not working


Tried starting code from terminal, but the error persits.


I pressed on retry

👍 1

Yeah, at least on emacs starting from terminal helps too, weird


That doesn't look right. Is this a deps.edn or a Leiningen project?


Do you have clojure when you try in the terminal?




so you should run clojure -A:dev:test -Spath which is what clojure-lsp is trying to run


so you don't have clojure installed at all, you need to install it


Ah, yes. For clojure-lsp to work you need that. The other features in Calva can cope without it, though.


You guys were absolutely right


So I am new to Clojure and taking a university course in functional programming and I did some math problems in Project Euler in order to practice


Turns out those were lein projects


and this university project is deps.edn


I should update the docs to early instruct to install clojure.


so they are two different things?


deps and lein


They are two different ways to start and manage your Clojure app, yes.


it's like maven vs gradle for Java


Some projects actually use both, but anyway. 😃


I think the auto formatting is kind off weak, or is it just me?


Depends on what you expect. Please start a convo about that in #CBE668G4R if you like.


Yes, ofc! Sorry.


No worries. I mainly thought it could interest the #CBE668G4R community to see what you expect as a beginner.

Jim Strieter15:11:50

Is the following O(1):

(into [] (rest (conj some-vector 42)))
If not, what is an O(1) way to do the same thing?


pouring N elements into a vector is always O(N)

Jim Strieter13:11:59

That's what I thought. Thanks!

Jim Strieter13:11:48

Yes. @U03L0CR870T’s suggested is exactly what I need. I needed an O(1) way to make a FIFO buffer.


if you want to replace the first item in a vec: (assoc v 0 item)

Brennan C.15:11:44

You may be looking for which will let you do (conj (subvec some-vector 1) 42)

🙌 1
Alex Miller (Clojure team)15:11:59

what are you actually trying to do? make a queue?

🙌 1

Is there a way to pass args to a java class as if by apply e.g. equiv of the following (which doesn’t work as I hoped) (apply Foo. [foo-arg1 foo-arg2])


the best solution imho is to define “constructor” function and call apply with it.

(defn newFoo [arg1 arg2] (Foo. arg1 arg2))
(apply newFoo [foo-arg1 foo-arg2])

👍 1

(map #(assoc % :bar (get-bar %)) foos)
is this not sort of a common pattern? Is this already the most succinct way to express this? I have a seq of maps and want to augment each with a :bar


this wont compile


there was a % to little yes


in general doing a thing to all items in a collection is map , that's the common pattern. in specific, deriving info is assoc + some function of the item


once I wrote a helper (label f :attr) that returned a function, but I thought it was less clear than the ordinary assoc+f


yea now that you say the alternative I start seeing how assoc just works


it's literally 2-3 characters more