Fork me on GitHub
#beginners
<
2022-03-02
>
Leon11:03:43

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.

jumar11:03:40

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.

delaguardo11:03:13

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)

delaguardo11:03:34

there is also bounded-count function that can help

jumar11:03:35

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.

zackteo14:03:52

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 https://docs.alluxio.io/os/javadoc/edge/alluxio/client/file/FileSystem.Factory.html#get-- 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 ....

ghadi14:03:47

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

ghadi14:03:52

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

ghadi14:03:29

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

😂 2
zackteo14:03:34

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

(.get (FileSystem$Factory.))

zackteo14:03:07

But clearly I'm wrong

ghadi14:03:19

static methods are (Class/method)

ghadi14:03:46

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

ghadi14:03:00

then (FileSystem$Factory/get)

zackteo14:03:00

right - I got it! 🙂

zackteo14:03:02

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

zackteo14:03:22

^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

dpsutton18:03:32

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

dpsutton18:03:53

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

sheluchin18:03:10

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.

dmegas19:03:26

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?

hiredman19:03:18

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

hiredman19:03:40

so you where starting an nrepl server during your build process

dmegas20:03:33

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?

hiredman20:03:37

Indication of what?

dmegas21:03:04

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?

ghadi22:03:12

can't answer categorically without an application in mind

ghadi22:03:28

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

hiredman22:03:52

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

hiredman22:03:53

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

hiredman22:03:28

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

hiredman22:03:40

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

😔 1
hiredman22:03:05

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)

hiredman22:03:36

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

hiredman22:03:44

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

hiredman22:03:27

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)

1
hiredman22:03:18

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

ghadi22:03:24

that's not a sad emoji worth statement

ghadi22:03:31

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 😛

hiredman22:03:51

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

hiredman22:03:11

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

hiredman22:03:02

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

😆 7
🙌 3