This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-03
Channels
- # adventofcode (91)
- # announcements (7)
- # aws (3)
- # babashka (69)
- # beginners (46)
- # calva (30)
- # cider (12)
- # clj-kondo (88)
- # cljs-dev (11)
- # cljsrn (1)
- # clojure (195)
- # clojure-dev (21)
- # clojure-europe (2)
- # clojure-italy (13)
- # clojure-nl (56)
- # clojure-spec (4)
- # clojure-sweden (6)
- # clojure-uk (27)
- # clojurescript (179)
- # core-async (2)
- # cryogen (1)
- # cursive (2)
- # data-science (1)
- # datomic (57)
- # fulcro (15)
- # graalvm (9)
- # instaparse (6)
- # joker (18)
- # juxt (9)
- # leiningen (6)
- # off-topic (20)
- # other-languages (10)
- # pathom (5)
- # re-frame (20)
- # reitit (2)
- # rewrite-clj (5)
- # shadow-cljs (78)
- # sql (34)
- # tools-deps (128)
- # uncomplicate (16)
- # vim (6)
i've been banging my head against this bizarre error message for a while now, wondering if i can get some help:
(defn directions-to-lines [directions]
((reduce reduce-directions {:lines () :position [0 0]} directions)) :lines)
(directions-to-lines wire)
i get Wrong number of args (0) passed to: clojure.lang.PersistentArrayMap class clojure.lang.ArityException
, but when i evaluate the body directly:((reduce reduce-directions {:lines () :position [0 0]} wire)) :lines)
Happens to the best of us. Are you using an editor with paren-matching?
Hello, stupid question: how do I do nested loops? I need a classic
for i = 0; i< 10; i++
for j = 0; j< 10; j++
check this example https://www.lvguowei.me/post/nested-for-loops-in-clojure/
Do you absolutely need a loop? If you just need the i, j
pairs, clojure.math.combinatorics/cartesian-product
can get you all combinations of i, and j, which you can map a function (your inner loop body) over. Feels a bit more idiomatic to me, but I am equally beginner
Nested dotines
is prob easiest
But it depends if you are making something (then use for
)or doing side effects
How do I run a single clojure file from the CLI if I have a -main
function? The filename is manhattan.clj
and ns is manhattan.core
but running clj manhattan.clj
doesn't seem to be working when I just do a println
in -main
. It's not printing anything to the console.
@nicholas.jaunsen main methods can be executed with the -m
option, but I think the file has to be on the classpath (typically in the src
dir)
Ah, I just imported clojure.main
and passed my entry point to the main function from that namespace
Hi all, I'm just getting started on Clojure/ClojureScript for a small-ish full-stack web app for my colleagues. After randomly stumbling around, I came up with a luminusweb/re-frame/graphql foundation and it seems to work OK (so far). However, I'm blown away by spec (I'm a Scala guy, usually) and I'd like to use that, in hopefully the right way from the start. Can anyone suggest any similar full-stack apps on github or elsewhere that I could study, preferably using spec in a non-trivial way?
Not a codebase like you're looking for, but this is a useful reference on the ways you can use spec. https://corfield.org/blog/2019/09/13/using-spec/
I still have a load of really basic questions, such as where do people generally put the specs? In their own specs/
directory (separate from src/
, for example)? Do you put all of the specs in one place, under one ns, or scattered about, together with modules you are spec-ing?
That's also a question I also have. From what I read it's in src/
, either together in a specific ns or close to the functions they instrument
It depends. And that article answers that question as I recall?
Thanks. Yes, you did mention that you put the specs and predicates under a separate namespace. In src, I assume? I missed that the first time.
All source code goes under src
so it is on the classpath. Test code goes under test
and is added to the classpath for when you run tests.
An alternative option (which I find helpful) is to co-locate your specs with the ns they pertain to. e.g. if your folder structure was
src/
app.clj
route.clj
todo.clj
I would put todo
specific specs into the todo.clj
file and if there are specs that don’t fit into any of the namespaces themselves, I move them to app
…but this is a guideline and it really depends on your domain and app structure.Another thing to note is I do not opt to spec everything, but rather, the edges of the application. For example, maybe only the public API fns would be spec’d or important implementation details.
(def pos
{:u inc :d dec
:r inc :l dec})
(defn path-inc [cord [k v]]
(let [dir (if (contains? #{:u :d} k) 1 0)
choose #(update % dir (pos k))]
(take v (rest (iterate choose cord)))))
(defn trace-line [start dirs]
(let [llast #(last (last %))
reducer (fn [acc dir]
(conj acc (path-inc (llast acc) dir)))]
(->> dirs
(reduce reducer [[start]])
flatten
(partition 2)
rest
set)))
having a weird issue with the trace-line
function. For some reason it's returning a list of tuples and not a set of tuples even though I'm calling set in thread last macro
That seems difficult to understand given the code that you show. How certain are you that the code you show matches the code you are running? e.g. could you be running code older than what you have in your editor? Tried saving all files, starting a fresh REPL, and loading your code again?
ok, I quit the REPL and restarted it that fixed the issue. For some reason it wasn't updating the function def even though I reloaded the code several times
There are many many ways to reload code, depending upon editor /environment setup, so difficult for me to guess what might have been going wrong there.
In shadow-cljs, is there a way to re-enter the cljs-repl after leaving it with :cljs/quit
?
@mitchell_clojure how did you start it in the first place?
just by running (shadow/repl :app)
from the shadow nREPL server
running :cljs/quit
takes me out to the user
namespace and I am a little unclear on if the cljs repl persists or is reachable from there
Just note that when you exit it with :cljs/quit
you're left in a namespace that doesn't contain the shadow
alias
oh okay, so is it preferable to have two separate repls running?
oh awesome, that looks like exactly what I was looking for. will verify later when I get home! thank you very much!
Hi everyone! I can't seem to be able to catch errors thrown using Pedestal. I have a transaction function to Datomic that throws a clojure.lang.ExceptionInfo exception in the datomic on-prem transactor, which, according to Datomic documention, should also be thrown in the peer, so in my case through the database interceptor that tries to transact the faulty data. None of my interceptors have an :error function, but I have used io.pedestal.interceptor.error/error-dispatch to catch the errors at the end of the process. It does not seem to work. • Does an interceptor need its :enter function to be used on the request to have its :error function used on the way out? • If so what is the proper way to user error-dispatch (the resulting interceptor is the first in the route) • any other thoughts as to why I am not catching it (it's a POST request and it returns 201 created even if it didn't happen...) Thanks!
Is there a convenient way to use cider-load-buffer
without having an associated file? I just have a scratch buffer and I jacked into cider and I want to load the buffer into the REPL and play without without having a file on disk, but trying to load the buffer gives "Buffer 'my-buffer' is not associated with a file"
I do not know the answer but wanted to point out that there is a #cider channel