Fork me on GitHub

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?


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,


however, I am not familiar with IO in Clojure now

seancorfield02:09:41 -- 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


Although this library 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)

seancorfield02:09:39 and also ask in the #babashka channel


That's what some folks are using for shell scripting with "Clojure"...


thank you:slightly_smiling_face:

Kyle Brodie01:09:07

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.

Kyle Brodie01:09:22

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.

鉂わ笍 3

(assuming your-normal-process itself is eager)

馃挴 3
Kyle Brodie02:09:13

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.


Yeah, if the CSV file is unparseable, there's very little you can do: the library simply cannot recover from the error.

Endre Bakken Stovner06:09:42

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?

Endre Bakken Stovner06:09:36

I am guessing it means they can be extended at any time and place (before usage).

Alex Miller (Clojure team)12:09:43

It means that new extensions can be added at any time, without modifying the original definition

馃憤 3
Michael J Dorian12:09:27

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?

Alex Miller (Clojure team)13:09:55

for future questions, prob best to use #datomic (but I'd just leave it here now)

馃憤 3

(d/q '[:find ?title
         [?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 ...]
         [?movie :movie/year 1984]
         [?movie :movie/title ?title]] db)


@UNMBR6ATT this is a good resource (if you're not aware of it):

Michael J Dorian14:09:58

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)

Michael J Dorian16:09:25

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.

Michael J Dorian16:09:51

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.

parrot 3
Alex Miller (Clojure team)16:09:55

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. 馃檪

Michael J Dorian17:09:51

Definitely need to check that out, thanks!


Curious if anyone has experience turning clojure spec into json schema --- if it's viable/worth the effort?


I've done it


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)


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


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!