Fork me on GitHub

Is there a way one can check if a list of a map has more than one index? (meaning has more than 0 index) for example ({:game "God of war", :genre "Action/adventure"}, {:game "Elden Ring", :genre "Action-role play"}) . In this case the list of a map has index 0 and 1.


By index you mean an entry? If so, you can simply (> (count m) 1) I'm not sure why you are calling them an "index" and giving them numbers like 0 and 1 but note that maps are unordered.


btw count will realise all entries of lazy seq and in some cases might block (eg. (count (range))) in those case it is better to use combination of next and seq

(if (seq (next xs)) true false)


there is also bounded-count function that can help


Ah, sorry, I somehow missed the "list" part and thought it's a map, not a list of maps - sloppy reading. Anyway, the answer still more or less applies. @U04V4KLKC’s note about bounded-count might be useful if your collection is big and you don't want to realize it all.


May I know what is the equivalent of the following in clojure

FileSystem fs = FileSystem.Factory.get();
Am a bit confused cause it is a class in a class So am wondering am I right to do
(ns alluxio-test.core
  (:import [alluxio.client.file FileSystem]))
I'm not sure how to do the Factory I just know it would be something like (.get ....


Clojure refers to nested classes in the same way the JVM does: they get a dollar sign at the nesting FileSystem$Factory


jshell> java.nio.file.DirectoryStream.Filter.class.getName()
$2 ==> "java.nio.file.DirectoryStream$Filter"
when in doubt, you can use jshell to get the full class name using java syntax


(^^ what a 😲 suggestion for a Clojure room, eh?)

😂 2

Does this mean I need to change to FileSystem$Factory in my import and my first instinct is

(.get (FileSystem$Factory.))


But clearly I'm wrong


static methods are (Class/method)


first confirm that you have FileSystem$Factory imported by just typing that symbol at the REPL


then (FileSystem$Factory/get)


right - I got it! 🙂


I think generally I'm not too clear when things are static methods and whatnot. And it gets more confusing when I try to convert things to Clojure :x


^right I guess it is listed in the Javadocs

Hussein Khamis18:03:44

Hello everyone, has anyone used a library for translations with po? Read / write po files, scan code to find a tr called.

Hussein Khamis18:03:53

Maybe something like django-rosetta


Metabase does this. I’m not sure its a library but you can check it out


its quite complicated but we have separate processes that scan the code for translatable strings. At runtime the po files are turned into maps with the string to translate as the key, and then java.text.MessageFormat takes over from there


I need to run a few different tasks on separate schedules. Is it reasonable to use Mount to create a state out of each scheduled runner? I figure Mount would give me visibility of running schedules and the ability to start/stop them independently as needed.


I tried to embed an nREPL Server to my app by doing the following in one of my namespaces:

(:require [nrepl.server :refer [start-server]])
(defonce server (start-server :port 7888))
This broke my lein uberjar; it was getting stuck without any error messages. I was able to fix this by changing the above line to
(defonce server (delay (start-server :port 7888)))
and deref’ing it from my main namespace. Can anyone please help me understand why this was happening?


you are aot compiling and aot compilation runs top level forms as it compiles


so you where starting an nrepl server during your build process


Ah, I didn’t know that, it makes sense now, thank you very much! Do you happen to know if there is a way that I could get any indication for this during compilation?


Indication of what?


Wow, turns out I hadn’t understood the implications of what you said completely. I thought that trying to start the nrepl server while lein uberjar ’ing was causing some failure, for which I was expecting some indication of; turns out the nrepl server is starting just fine and waiting for connections, that’s why packaging is not moving forward. Thank you very much, I feel so much better now!

Nathan Rogers22:03:12

1. What is the "correct" way to network clojure applications? 2. If I'm providing a service is that typically done over HTTP? 3. Is there proprietary clojure protocols that enable intercommunication between clojure applications? 4. What library, standard are otherwise is recommended for HTTP? Sockets? Other?


can't answer categorically without an application in mind


it's a general purpose language, so it can do all the things you mentioned

Nathan Rogers22:03:52

Well, I don't know what ways clojure is able to either 1. communicate with other clojure applications 2. communicate with other clojurescript applications 3. consume general purpose apis over socket/http/other

Nathan Rogers22:03:10

like, maybe an overview or list of bonafide libraries


if you are asking if clojure has a batteries included rpc system, the answer is no

Nathan Rogers22:03:27

I though I saw a video that mentioned something about a communications protocol "baked into clojure" that allows the passing of fully formed clojure data over the wire?

Nathan Rogers22:03:35

that'd have been a few years back


otherwise, there are tons of libraries both in clojure and using anything in java or javascript that do all those things, so could be anything

Nathan Rogers22:03:53

maybe that was a protocol for the clojure db

Nathan Rogers22:03:09

or maybe that was low-level internal protocol

Nathan Rogers22:03:13

I can't rightly recall


clojure programs are themselves represented as data which is a neat capability to have for rpc


but no, there is no built in rpc stuff that ships with clojure itself

😔 1

in my experience (which by no means is complete) clojure programs typically speak http by embedding some http server in them (jetty, http-kit, undertow, aleph, netty's http stuff, etc)


and then that is used to serve various kinds of apis or content


second to http would be some kind of messaging "thing" kind of thing (rabbitmq, activemq-artemis, redis pubsub, etc)


there are other kinds of approaches, like you can use protocol buffers to define servers (I know some companies do this using the json encoding of protolbuffers, which is odd)


for data encoding, json remains king of heterogeneous environments, edn (a subset of clojure syntax) is ok to a point, but transit (basically edn but trying to take advantage of optimized codecs for other formats like json and msgpack) is very popular for communicating between clojure and clojurescript


that's not a sad emoji worth statement


RPC frameworks come and go

Nathan Rogers22:03:18

the sad emoji was I was hoping to find some recommendations, which I was provided after 😛


if you just want some kind of instant cluster thing, you might want to checkout jgroups


there is a great rhickey talk from a while back, The Language of the System which also might be of interest


there is a point in that talk where I yell "uuids" from the back of the room

😆 7
🙌 3