clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
Schpaa 2020-10-02T09:00:41.387400Z

Anyone know of a library that gives ansi colors in terminal output (that supports babashka)?

borkdude 2020-10-02T09:04:38.387600Z

@schpaencoder https://github.com/borkdude/babashka/issues/547

❀️ 1
restenb 2020-10-02T09:12:05.388200Z

(filter identity [1 2 3 nil 4 false true 1234]) => [1 2 3 nil 4 false true 1234]

restenb 2020-10-02T09:12:21.388600Z

from my repl. am I going crazy? isn't nil and false supposed to be filtered out?

2020-10-02T09:13:12.389100Z

Are you sure you're evaluating the full filter expression and not just the vector?

restenb 2020-10-02T09:15:04.389500Z

i just copy-pasted the second example from the docs https://clojuredocs.org/clojure.core/identity

2020-10-02T09:17:51.390700Z

> I going crazy? Seems so. Filter returns lazyseq, not vector. So you can not get [] as its output

restenb 2020-10-02T09:22:17.391100Z

that's a good point. so my REPL must just be returning the vector somehow

restenb 2020-10-02T09:23:04.391400Z

i restarted it and now it is correct: (filter identity [1 2 3 nil 4 false true 1234]) => (1 2 3 4 true 1234)

restenb 2020-10-02T09:23:23.392100Z

god knows what that fuckness was

vlaaad 2020-10-02T10:02:42.392500Z

that’s easy

vlaaad 2020-10-02T10:03:24.393Z

$ clj
Clojure 1.10.1
user=> (clojure.main/repl :eval last)
user=> (filter identity [1 2 3 nil 4 false true 1234])
[1 2 3 nil 4 false true 1234]

πŸ’ͺ 1
yury.solovyov 2020-10-02T11:34:41.394900Z

hey, what might be the reason I'm getting different carmine response behavior when I run it in repl or via clj ?

yury.solovyov 2020-10-02T11:35:04.395300Z

e.g. it does not print responses via clj

slipset 2020-10-02T13:51:08.398300Z

Sorry if this is a faq but say I have a url as a string, and I'd like to convert it to a keyword, (keyword "<http://foo.bar.baz>") will create me a namespaced keyword, which is not really what I want because it doesn't round trip as I'd like it to:

user&gt; (name (keyword "<http://foo.bar.com>"))
;; =&gt; "/foo.bar.com"
user&gt;
Is there a way to construct a non-namespaced keyword from a string that contains a / and how would one go about doing it?

Darin Douglass 2020-10-02T13:53:53.398400Z

something like this should work:

user=&gt; (name (keyword "<http://foo.bar.com>"))
"/foo.bar.com"
user=&gt; (name (keyword "" "<http://foo.bar.com>"))
"<http://foo.bar.com>"
user=&gt;

dpsutton 2020-10-02T13:54:04.398900Z

What’s your desire for this to be a keyword?

Darin Douglass 2020-10-02T13:54:06.399Z

essentially, explicitly provide an empty namespace

βž• 1
slipset 2020-10-02T13:55:36.399600Z

I would hate to admit it, but it's for storing it in mongo....

slipset 2020-10-02T13:56:54.400800Z

api reads json where we do (cheshire/parse-string bla true) and then stuff it to mongo where the mongo driver probably uses name to turn the keys into string.

slipset 2020-10-02T13:57:30.400900Z

right. This feels so wrong πŸ™‚

teodorlu 2020-10-02T13:58:06.401100Z

Or provide a nil keyword,

user=&gt; (namespace (keyword "" "<http://foo.bar.com>"))
""
user=&gt; (namespace (keyword nil "<http://foo.bar.com>"))
nil

user=&gt; (keyword "" "<http://foo.bar.com>")
:/<http://foo.bar.com>
user=&gt; (keyword nil "<http://foo.bar.com>")
:<http://foo.bar.com>

Darin Douglass 2020-10-02T13:58:14.401300Z

yep πŸ™ƒ just like keywordizing a url. mongo makes people do weird things

slipset 2020-10-02T14:02:52.401600Z

It's all mongos fault.

dpsutton 2020-10-02T14:05:12.402Z

you have no way to put a string into your database?

p-himik 2020-10-02T14:05:33.402100Z

name on a string yields a string.

p-himik 2020-10-02T14:06:08.402300Z

So unless it actually complains about something not being a keyword, using strings should be fine I imagine.

slipset 2020-10-02T14:12:33.402500Z

Yeah, but the true flag to cheshire instructs it to keywordize the keys.

slipset 2020-10-02T14:12:51.402700Z

Which one might argue is a bad idea, but that ship has sailed.

p-himik 2020-10-02T14:13:26.403300Z

Ah, right.

slipset 2020-10-02T14:13:47.403900Z

We do, but at some point we decided to keywordize the keys of our maps. One could argue if that was a good idea or not, but that ship has sailed.

2020-10-11T00:41:34.319600Z

keywordize keys strikes again!

dpsutton 2020-10-02T14:14:50.405200Z

oh its the key in the map? i suppose you've thought about making it a {:type :url :value "<https://blah.com>"} then and that can't work?

dpsutton 2020-10-02T14:15:25.406Z

that's a pickle

slipset 2020-10-02T14:16:06.407Z

Haven't thought about it yet. Thing is that I needed to store some rewriting rules in mongo, basically I needed to store "whenever you see http://foo.bar.baz, rewrite it to 'email'"

slipset 2020-10-02T14:16:42.407700Z

For this, a map makes perfect sense, since you can just feed it to set/rename-keys

slipset 2020-10-02T14:17:14.408400Z

But, I wasn't aware at the time that we'd need to rewrite url-keys.

slipset 2020-10-02T14:19:16.409300Z

@dpsutton but I will use your input to hammock this over the weekend. Thanks!

πŸ‘ 1
quadron 2020-10-02T16:58:09.411800Z

are there any indexes other than the commits on git repos that demonstrate the "liveliness" of a certain lib? I ask this since it seems for clojure some libs are used but not really under active development

ghadi 2020-10-02T17:01:55.412500Z

this is a commonly asked question, but churn isn't really valued in the community

ghadi 2020-10-02T17:02:13.412900Z

some libs just finish

ghadi 2020-10-02T17:02:32.413500Z

e.g. clojure data.csv

ghadi 2020-10-02T17:03:23.414500Z

you could look a library's usage with https://grep.app

πŸ‘ 1
dharrigan 2020-10-02T17:11:55.418600Z

I certainly use libraries that haven't been touched in a few years, because they work - and work very well. I'm happy with that aspect of the Clojure community. It allows me to focus on my code, and not checking every few days if a new version of the library has come out πŸ™‚ A totally super benefit too, is given the great interop of Clojure, I can pull in a regular Java library and use that too. I love it!

dharrigan 2020-10-02T17:12:48.419300Z

(as someone who dabbles also in Javascript, the churn there is astronomical!)

emccue 2020-10-02T17:17:23.420Z

on that note maybe we need a "done" badge on github that doesn't read as "not maintained"

🎯 1
1
emccue 2020-10-02T17:17:37.420500Z

"stable"?

quadron 2020-10-02T17:17:55.420800Z

or something like a "health-meter"

emccue 2020-10-02T17:18:03.421Z

nah, health implies metrics

emccue 2020-10-02T17:18:32.421500Z

which implies active development

1
emccue 2020-10-02T17:19:08.422400Z

the conceit here is that a library is finished and does its task so there is just "no more work to do" on it

emccue 2020-10-02T17:19:39.423Z

the state of the world in JS is something like "while a library is alive, it is a tiger and when its dead its a dead tiger"

🐯 1
emccue 2020-10-02T17:20:09.423800Z

whereas the common observation for clojure is that "An active library is like a tree, an inactive library is a house"

πŸ‘ 1
emccue 2020-10-02T17:21:06.424700Z

so how to at a glance determine if something is a finished product or an abandoned experiment is something

dharrigan 2020-10-02T17:21:31.425300Z

I like the analogy of an inactive library is like a house πŸ™‚

emccue 2020-10-02T17:23:32.425900Z

it mostly just comes because clojure dealing with data structures directly

emccue 2020-10-02T17:23:46.426200Z

so stuff like clojure.data.csv is just...done

emccue 2020-10-02T17:23:56.426500Z

it parses a data format into our "standard" for data

emccue 2020-10-02T17:24:48.427400Z

which avoids the sort of "exponential bikeshed" of javascript and java and all the other nominally typed things out there

emccue 2020-10-02T17:27:00.429100Z

public final class Row implements Iterable&lt;String&gt; {
    // ...
    String get(int i);
}

public final class Csv {
    public static Iterable&lt;Row&gt; parse(InputStream contents);
}

emccue 2020-10-02T17:27:01.429300Z

vs

emccue 2020-10-02T17:27:53.430500Z

public class CsvReader {
    // ...
    CsvReader(Options opts) { /* ... */ }

    List&lt;List&lt;String&gt;&gt; parse(InputStream is);
}

emccue 2020-10-02T17:28:11.430800Z

or whatever

emccue 2020-10-02T17:29:46.431200Z

its just "maybe too big for memory" -> lazy seq,

emccue 2020-10-02T17:29:55.431500Z

"probably not too big for memory" -> vector

emccue 2020-10-02T17:30:23.432200Z

for csv, there might be too many lines in a big file, but no individual line will be a gb probably

emccue 2020-10-02T17:30:39.432300Z

emccue 2020-10-02T17:30:48.432800Z

csv reading done, next problem

πŸ‘ 1