This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-03
Channels
- # announcements (11)
- # atom-editor (8)
- # aws (16)
- # babashka (34)
- # beginners (59)
- # calva (32)
- # cider (8)
- # clj-kondo (43)
- # cljs-dev (52)
- # clojure (26)
- # clojure-europe (11)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-spec (16)
- # clojure-uk (44)
- # clojurescript (5)
- # core-async (21)
- # cursive (14)
- # datomic (53)
- # figwheel-main (4)
- # fulcro (5)
- # graphql (6)
- # java (3)
- # kaocha (5)
- # leiningen (6)
- # local-first-clojure (1)
- # malli (25)
- # off-topic (40)
- # other-languages (1)
- # pathom (5)
- # pedestal (3)
- # re-frame (4)
- # reitit (2)
- # reveal (8)
- # rum (21)
- # sci (16)
- # shadow-cljs (90)
- # spacemacs (8)
- # tools-deps (10)
- # vrac (6)
- # xtdb (12)
recently I am interested in writing script with Clojure, I don't know if there is any example, can someone help me out?
@steiner3044 You'll need to be a bit more specific -- what sort of script do you want to write? What are you already familiar with?
How familiar are you with Clojure so far? What tutorials have you already read? This one? https://clojure.org/guides/getting_started
eh, bash
is I want to write, I can write bash
script, but I don't like its strange syntax, so I want to use other language,
https://clojuredocs.org/clojure.java.io -- but it's all based on Java IO and you may find it worse than bash...
If you want to do file manipulation, you'll need to use Java interop and stuff like https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html
Although this library https://github.com/clj-commons/fs might make your life a bit easier
oh, sh*t you mean when start clojure, it is needed to run JVM? if it is, it there any example about writing script in Scheme??
You might want to look at babashka which is a native application (but a slightly limited ecosystem of libraries)
https://github.com/borkdude/babashka and also ask in the #babashka channel
That's what some folks are using for shell scripting with "Clojure"...
You might also find this discussion helpful @steiner3044 https://clojureverse.org/t/how-to-replace-every-day-bash-commands-with-babashka/6459
How would I catch an exception thrown in a lazy sequence and continue? I'm using org.clojure/data.csv
and a CSV error is being thrown for one of the rows but, at least for now, I want to just skip those rows and continue
@kyle That's going to depend on exactly what's causing the exception and where.
If the exception is coming from inside that library and it's failing to produce more elements of the sequence, you won't be able to fix that without patching the library. If the exception is coming from your own code, you probably could make it more robust.
Its coming from inside the library. I am transforming the lazy seq produced by org.clojure/data.csv
with map
. I don't know how I would continue without translating it to a (loop)
and getting the first element of the lazy sequence inside a try-catch
Well, you could map "bad" rows to nil
and then filter those out -- if data.csv
continues to produce elements beyond the row you cannot consume.
(filter some? (map (fn [row] (try (your-normal-process row) (catch Exception _))) data-csv-rows))
Would (keep #(try (your-normal-process %) (catch Exception _)) data-csv-rows)
be equivalent to this?
Yeah, actually it would... although of course both solutions would fail if your-normal-process
could return nil
I guess (but then maybe doseq
is a better way to process rows 馃檪 ). I tend to forget about keep
but I think it's a nicer solution in this case. Thanks.
Does that work if (first csv-lazy-seq)
would throw if the first CSV row in the file is invalid? It is throwing a plain java Exception
Right, that goes back to my question about exactly where the exception is originating.
This is the source of the throw if you're curious https://github.com/clojure/data.csv/blob/data.csv-1.0.0/src/main/clojure/clojure/data/csv.clj#L37
Yeah, if the CSV file is unparseable, there's very little you can do: the library simply cannot recover from the error.
I am new to protocols and mixins. In The Joy of Clojure, the authors write that mixins and protocol extensions are fully open. What does fully open mean here?
I am guessing it means they can be extended at any time and place (before usage).
It means that new extensions can be added at any time, without modifying the original definition
Hey friends, I'm trying to do a basic query in datomic and the docs aren't quite clicking for me. I have this test dataset:
(def first-movies [{:movie/title "The Goonies"
:movie/genre "action/adventure"
:movie/release-year 1985}
{:movie/title "Commando"
:movie/genre "thriller/action"
:movie/release-year 1985}
{:movie/title "Repo Man"
:movie/genre "punk dystopia"
:movie/release-year 1984}])
And I have this query (d is an instance of the database that the movies have been transacted into)
(d/q '[:find ?title
:where ;[]
[?title :movie/title ?title] ] db)
this returns a list of all movie titles, as per the datomic tutorial, but what I want is a list of all movie titles from movies that came out in 1984. In other words, my result set should be ["Repo Man"]
What can I put in the commented out where clause to make this happen?for future questions, prob best to use #datomic (but I'd just leave it here now)
(d/q '[:find ?title
:where
[?movie :movie/year 1984]
[?movie :movie/title ?title]] db)
will give you a set of tuples, or if you want just the titles:
(d/q '[:find [?title ...]
:where
[?movie :movie/year 1984]
[?movie :movie/title ?title]] db)
@UNMBR6ATT this is a good resource (if you're not aware of it): http://www.learndatalogtoday.org
Thank you! That worked, I'll check out that page!
The reason that query works, is because you use the same binding ?movie
in two clauses; which means it will do a "join" and only match datums such-that :movie/year
is 1984
and :movie/title
is ?title
for the same entity ?movie
As a point of learning, What is ?movie going to return if we examine it? ?movie is actually going to be an entity ID that matches for the movie/year 1984 and movie/title ?title (in this case, unbound var that will resolve to anything provided other where clause lines are satisfied)
Would that ID be in the form of a long number? I think that was actually the result I got for one of my attempts
Yes something like that. It might look like #GARBLE i don't recall what shape they take off the top of my head.
Interesting. Thanks!
You could also keep 1984 agnostic as ?year and pass in a value for ?year immediately after the where clauses. Something to keep in mind as you develop queries.

Have fun!
entity ids are longs
so it would look like a big number
@UNMBR6ATT I gave a talk last year that covers datalog queries step-by-step; some people have found it useful. Perhaps you may too. 馃檪 https://www.youtube.com/watch?v=oo-7mN9WXTw
Definitely need to check that out, thanks!
awesome
Curious if anyone has experience turning clojure spec into json schema --- if it's viable/worth the effort?
I did it to describe an api to our front end guys, but in the end it wasn't enough, you can describe data types with it, but you can't describe an operation (do this, then you get this result) and that was more of what I needed
but it is neat, and atleast for the trivial things, trivial, because you can get the un-eval'ed form of a spec out of a spec, you just write an interpreter for those
yeah, i was wondering how complete of a json spec you can create. I would only be describing data (preferably to the level of "if you pass this, then this other thing is required"). Actually i didn't know you could specify operations in json schema, or missing what you mean there... sounds like swagger-like (which i don't need)
one impl of spec -> json schema in spec-tools: https://cljdoc.org/d/metosin/spec-tools/0.10.4/doc/json-schemas
cool. i think i need to see if/how to compose specs. For example, have a basic spec, where little/nothing is required, but be able to layer on specific/more stringent cases.
yeah, swagger like (but of course swagger didn't work because it isn't a rest api, and there are async parts, etc)
Hi all ! Quick question. I鈥檓 using reitit router on the frontend and the backend. How can I forward urls to the frontend router? I have routes which work like /#/great/person
. However, when I navigate to that route using the browser, I鈥檓 redirected to #/
instead of the route.
Not that you won't get an answer here, but check out https://clojurians.slack.com/archives/C7YF1SBT3
I'm willing to bet the chances of finding someone who knows the specs of that library are higher there
Sweeet! I鈥檒l try there! Thank you!