beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
West 2021-02-17T05:29:41.272800Z

Hey guys. I’m hand-rolling my own solution for a static site generator. Now I’d like to have multilingual support, I’m wondering what the best way to go about that is. I assume I’ll have to deal with routing eventually, using something like bidi or reitit. What other things should I consider in order to keep things neat? https://gitlab.com/wildwestrom/cljs-tailwind-static/-/tree/personal-site

zackteo 2021-02-17T08:02:01.275600Z

Hi everyone, I'm looking for something I encountered before (but can't think of the right search terms). What is the website that analyses clojure code and helps you to "fill in the blanks" of the code using core.logic (?) which is based a haskell's implementation

zackteo 2021-02-17T08:03:22.276900Z

Something simliar to lein kibit it helps to fill in the blanks based on the output

phronmophobic 2021-02-17T08:15:28.277200Z

not core.logic based, but a similar idea, https://borkdude.github.io/re-find.web/

borkdude 2021-02-17T08:31:44.277400Z

Hosted here: https://borkdude.github.io/re-find.web/

zackteo 2021-02-17T08:33:51.277700Z

Thanks! πŸ™‚

robertfw 2021-02-17T10:33:17.278Z

I haven't seen this before, this looks quite useful! I also like the way the examples slowly cycle, that is a really nice touch that I have not seen before.

borkdude 2021-02-17T10:46:08.278200Z

Thanks :)

popeye 2021-02-17T11:50:24.280100Z

Team I am trying to add all the name from database to vector and I wrote below code

popeye 2021-02-17T11:50:25.280300Z

(let [name (.next list-of-statement)
            v (conj [] (->> name (.getName) (.toString)))]
        v)

popeye 2021-02-17T11:50:39.280700Z

it returns nil because of immutability

popeye 2021-02-17T11:50:51.281100Z

how can I get all the names into vactor from database

2021-02-17T11:59:13.281200Z

this code can’t return nil because (conj [] …) will return a vector

popeye 2021-02-17T11:59:45.281400Z

ya empty vector,, how can I append values?

popeye 2021-02-17T11:59:52.281600Z

@delaguardo

2021-02-17T12:01:38.281800Z

empty vector or [nil]?

2021-02-17T12:01:39.282Z

Even (conj [] nil) returns [nil] , i.e. a vector with one element (which is nil), so I don't see how that expression you gave can possibly return an empty vector.

πŸ‘ 1
popeye 2021-02-17T12:02:20.282300Z

i want to add each value of (->> name (.getName) (.toString))

2021-02-17T12:02:27.282500Z

is it possible that this peace is working in bigger context? I’m expecting you are trying to append an element to vector in a loop

Daniel Stephens 2021-02-17T12:03:10.282700Z

is list-of-statements an iterator? If so you could use iterator-seq to turn it into a seq which is a lot easier to work with. Then you can use more standard/idiomatic clojure.

(do (defn db-values [] (iterator-seq all-db-vals-iterator))

    (defn db-value-name [db-value] (-> db-value (.getName) str))

    (defn db-value-names (->> (db-values)
                              (map db-value-name))))

2021-02-17T12:03:16.282900Z

Is list-of-statement a Java Iterator object?

popeye 2021-02-17T12:03:22.283100Z

(recur (.listStatements name) giving me infinite object

popeye 2021-02-17T12:03:44.283300Z

yes @andy.fingerhut

2021-02-17T12:04:11.283500Z

See comment above about iterator-seq which looks like good recommendation

aratare 2021-02-17T13:23:34.284500Z

Hi there. Can anyone give me a recommendation on what good mock/spy/stub testing library to use in Clojure/Script? Thanks in advance.

aratare 2021-02-17T13:25:13.284600Z

Did a quick googling and there's https://github.com/alexanderjamesking/spy but I'm just wondering what other good library I might miss out on πŸ™‚

oly 2021-02-17T14:17:13.288Z

You can also use with-redefs fn's from the standard library to mock out functions I do this in tests to avoid a db hit and return the rows I need for my test if your not aware of these functions.

Illia Danko 2021-02-17T14:19:16.289200Z

Good day. I'm curious is there any guide about the argument position convention of clojure.core? I know some excerpts are: β€’ Object as the first argument β€’ Sequence as the last argument But every time I confuse where to put a numeric argument and also the last bullet not 100% truth.

2021-02-17T14:31:10.289300Z

some info about that topic - https://groups.google.com/u/2/g/clojure/c/iyyNyWs53dc not complete answer thou

2021-02-17T14:49:45.289500Z

the best way (imho) to get advantage from mocking/stubbing/spying is to make such ability first-class citizen in your application. libraries for dependency injections will help a lot there. You could have a look at integrant for example.

Illia Danko 2021-02-17T15:12:39.289700Z

thank you

aratare 2021-02-17T16:13:42.290300Z

Thanks guys. I just need a way to do some simple testing for a small project I'm working in. At this scale I don't think I'd need something like Integrant, but thanks regardless πŸ™‚

Eamonn Sullivan 2021-02-17T17:27:31.292600Z

Hopefully a quick one: Is there a usual approach for mocking a function to first throw an exception and then return something else? I'm trying to test a catch clause. In mockito I would have done something like andThen ...

dpsutton 2021-02-17T17:28:49.293Z

like the first invocation would throw and subsequent invocations would return a value?

Eamonn Sullivan 2021-02-17T17:29:17.293500Z

yes, that's what I'm doing in this particular case.

Eamonn Sullivan 2021-02-17T17:30:03.294300Z

But having a pattern for returning one value, then another, etc., would be useful. The thing I'm mocking is making a REST call and returning the response, so it's not pure.

Eamonn Sullivan 2021-02-17T17:31:39.295500Z

In another project, I did this with an atom holding a list and then popped them, but I must have done it wrong, because it's flaky. I'm hoping someone has a tried and true pattern.

Eamonn Sullivan 2021-02-17T17:32:21.296200Z

Or it's just a feature of clojure.test I'm missing, and I don't have the right terms to google.

dpsutton 2021-02-17T17:37:19.297800Z

clojure test doesn't have any mocking functionality. its just assertions and such. if you're single threaded its possible to use with-redefs and temporarily replace things with functions that do what you want. if you've got a system engineered where you construct a system graph, you could construct it with subsystems that do what you want

dharrigan 2021-02-17T17:38:29.298Z

For mocking out REST calls, I use wiremock

dharrigan 2021-02-17T17:38:47.298400Z

a bit like this https://github.com/kelveden/clj-wiremock

Eamonn Sullivan 2021-02-17T17:39:29.299100Z

Ah, yeah, that's what I use in Scala (the Java version of that). I always forget I've got the whole JVM world to draw on...

dharrigan 2021-02-17T17:39:40.299400Z

indeed, tis a beauty πŸ™‚

dharrigan 2021-02-17T17:41:45.299800Z

(wmk/with-stubs
     [{:req [:GET (str "/tenant/v1/" rsc-tenant-id)] :res [200 {:body (utils/map->string {:tenantCode rsc-tenant-code})}]}]
     (->> (generate-email-payload rsc-investigations rsc-tenant-code 12 app-config)
          (expect (assoc rsc-email-configuration :body email-body))))))

dharrigan 2021-02-17T17:41:49.300Z

bit like that πŸ™‚

Eamonn Sullivan 2021-02-17T17:43:33.300900Z

Right, so I can make the first attempt return some non-200 (404) and then return a 200. Got it. Looks like what I want. Thank you!

dharrigan 2021-02-17T17:43:55.301300Z

yup

mruzekw 2021-02-17T17:49:52.302100Z

Is there a CLJ(S) library out there to make and subscribe to cursors from an atom?

sova-soars-the-sora 2021-02-17T18:01:29.302200Z

there's no access to the jvm from scala?

sova-soars-the-sora 2021-02-17T18:02:30.302400Z

Maybe relevant https://github.com/tonsky/rum#cursors

Eamonn Sullivan 2021-02-17T18:04:04.302700Z

Yes, of course, but Clojure is so different that it just doesn't occur to me as easily. I just forget!

PB 2021-02-17T19:20:03.303200Z

Is there a good way to make a transit api request from the CLI?

chaow 2021-02-17T20:50:20.311100Z

I have a list of dictionaries as such:

[{:id 1 :key 1 :value 1}
 {:id 1 :key 0 :value 0}
 {:id 2 :key 1 :value 1}
 {:id 2 :key 0 :value 0}]
and id like to group this list by id as such:
[{:id 1 :attributes [{:key 1 :value 1} {:key 0 :value 0}]}
 {:id 2 :attributes [{:key 1 :value 1} {:key 0 :value 0}]}]
This wouldnt be too hard in python but im scratching my head for how to write this in clojure πŸ˜…

2021-02-17T20:52:29.312100Z

clojure.core/group-by or clojure.set/index

chaow 2021-02-17T20:52:52.312500Z

thanks! will go do some doc reading πŸ™‚