This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-10
Channels
- # admin-announcements (1)
- # aleph (1)
- # asami (9)
- # babashka (30)
- # beginners (83)
- # calva (8)
- # cherry (4)
- # cider (4)
- # clj-kondo (15)
- # cljs-dev (11)
- # cljsrn (8)
- # clojure (85)
- # clojure-europe (87)
- # clojure-losangeles (9)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (3)
- # clojurescript (12)
- # community-development (5)
- # conjure (1)
- # core-typed (3)
- # datomic (21)
- # docker (13)
- # emacs (13)
- # funcool (1)
- # google-cloud (1)
- # graalvm (12)
- # gratitude (14)
- # holy-lambda (6)
- # introduce-yourself (18)
- # lsp (15)
- # malli (6)
- # matcher-combinators (15)
- # nbb (15)
- # off-topic (37)
- # pathom (31)
- # portal (23)
- # rdf (3)
- # releases (2)
- # reveal (2)
- # sci (4)
- # scittle (3)
- # shadow-cljs (14)
- # squint (2)
- # tools-deps (29)
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? 🙂
I've gone ahead and placed the project into a public repo here https://github.com/pkingstonxyz/pkingstonxyz-clj
oh no you didnt have to share the whole thing. see https://kit-clj.github.io/docs/guestbook.html for correct usage of query-fn
@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.
As a high level overview
Also see https://clojurians.slack.com/archives/C053AK3F9/p1668019928420969 informative thread from yesterday about best practices, particularly when (not) to use macros.
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).
When learning macros in Lisp I got a great deal out of On Lisp by Peter Seibel, which has a https://gigamonkeys.com/book/macros-defining-your-own.html 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 https://github.com/ruricolist/spinneret, for example.
@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
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.
You might need to run the command Install command line code or whatever it is named in VS Code first.
Are you sure you didn't press Ignore
button on that classpath warning? if so, you may find some features not working
so you should run clojure -A:dev:test -Spath
which is what clojure-lsp is trying to run
Ah, yes. For clojure-lsp to work you need that. The other features in Calva can cope without it, though.
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
I should update the http://calva.io docs to early instruct to install clojure.
No worries. I mainly thought it could interest the #CBE668G4R community to see what you expect as a beginner.
Is the following O(1):
(into [] (rest (conj some-vector 42)))
If not, what is an O(1) way to do the same thing?That's what I thought. Thanks!
Yes. @U03L0CR870T’s suggested is exactly what I need. I needed an O(1) way to make a FIFO buffer.
You may be looking for https://clojuredocs.org/clojure.core/subvec which will let you do (conj (subvec some-vector 1) 42)
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])
https://stackoverflow.com/questions/26212769/apply-for-java-constructors There are some ways to do that but not in the core
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])
(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
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