This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-16
Channels
- # adventofcode (43)
- # announcements (31)
- # aws (2)
- # babashka (58)
- # babashka-sci-dev (4)
- # beginners (107)
- # calva (11)
- # cider (25)
- # clj-commons (8)
- # clj-kondo (24)
- # clojure (35)
- # clojure-argentina (1)
- # clojure-europe (25)
- # clojure-italy (5)
- # clojure-nl (11)
- # clojure-norway (39)
- # clojure-spec (11)
- # clojure-uk (3)
- # conjure (2)
- # core-async (19)
- # cursive (33)
- # data-science (2)
- # datomic (50)
- # deps-new (1)
- # emacs (3)
- # events (4)
- # figwheel-main (10)
- # fulcro (63)
- # graalvm (7)
- # holy-lambda (17)
- # introduce-yourself (1)
- # java (15)
- # jobs (1)
- # jobs-discuss (7)
- # malli (24)
- # meander (16)
- # nextjournal (19)
- # off-topic (2)
- # polylith (4)
- # portal (10)
- # re-frame (3)
- # reagent (19)
- # reitit (14)
- # releases (2)
- # remote-jobs (1)
- # reveal (19)
- # shadow-cljs (1)
- # sql (21)
- # testing (4)
- # xtdb (22)
Hey guys, am looking for a clojure library to access elasticsearch. Am using latest version of elasticsearch (7.16.1) and already tried https://github.com/clojurewerkz/elastisch, but it looks like it does not support elasticsearch version 7. For example when I create an index I get 405 error message and it looks like elastich uses POST for creating index and since elasticsearch version 6, index is created using PUT and not POST. If anyone knows any other library that can be used with elasticsearch version 7, please let me know š
you can always use the java library for elasticsearch
I'm going through book Clojure for the brave and true, and they mention this is operation
are operators something that only a language can specify, or can a macro make a new operator?
you can make new operators
via macro?
or via functions
operators are just functions/macros
so what i considered a function, is really just an operator?
assuming this is what they mean
@filip.strajnar https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L986-L996
I don't think that's the same, because in the book, they mention branching constructs as operators too
ah, well, then it's all functions and macros then
Any form (rator rand ...) The first element is the operator. It can be a function which means it will be evaluated at run time, or a macro which will be evaluated at compile time
or a built in operator? or is in built operator just a function?
i think it's fine if i just assume in built operator is just a functions really
"Operators" are not a thing in Clojure - that tutorial is wrong (or trying to give you a story that might relate from another language)
what is a thing then
Cora recommended that book
I'm actually not a big fan of that book. I love Getting Clojure, though.
in other languages, there are syntactic operators defined in the language syntax
in Clojure the first element in a parenthesized expression is "a thing that can be invoked". if you want to call that position the "operator" that's ok, but it's important that it's not a fixed set of things in the syntax
so, if we decide to call the first position operator, operator is either a function or a macro, either pre-defined or in built in the language?
generally the things to be invoked are either functions (almost everything) or special forms (defined by the language)
things like + are just functions provided in clojure.core
it's also safe to assume that every time i use ()
, i'm invoking / evaluating an expression?
except for '()
, which is un evaluated list?
Thereās actually a special case for ()
Whenever you see (a b c)
then that means to evaluate something (treating a
as a function and the others as arguments).
Whenever you see '(a b c)
then the quote has prevented evaluation, and itās a list of 3 elements.
Whenever you want an empty list, you can say '()
, but the special case I mentioned is: ()
The empty list canāt be calling a function, so instead itās just treated as a literal empty list.
So (= () '())
returns true.
(identical? () '())
also returns true
I would be a little cautious about promising that identical?
returns true in such cases. It might happen to in the current implementation, but I wouldn't be surprised if you can find ways to construct two non-identical empty lists.
That is a minor side-nitpick comment, though, not the main point.
TBH, I wasnāt sure if it would, but I thought it might, and sure enough, it did. After all, theyāre both just clojure.lang.PersistentList/EMPTY
(this isnāt a conversation to have in this thread though)
lists are evaluated by invoking the first element with the rest of the elements as args
'() is special only because of the quote, which says to read, but not evaluate
but other than that, when i see ()
, clojure is evaluating?
you might find https://clojure.org/guides/learn/syntax a helpful starting point on the basics
it covers most of this
i already read this, but coming back to it, i understand it better
thanks
On a pedagogical note, itās also generally beneficial to get a basic working model that is not comprehensive, and let your understanding and complexity of your model increase with time. Chemistry, math, physics, economics, probably everything, all work like this when we learn. Understanding that image you just posted is probably a great starting point for a good while
I have a vector of words and I want to remove the empty ones, which of the following would you use?
(remove empty? words) ;; close to the semantics of the goal but uses a double negative
(filter seq words) ;; common idiom but not sure if the intent is as clear to the casual reader
(filter seq words)
is what iād go with. that idiom is clear to the casual Clojure reader
I always prefer remove
over filter
- I think as the verb here it says what you want most closely
"filter" as a word is always a little ambiguous as to whether you are filtering things out or in. clearly it's "in" in Clojure, but from an English point of view I think it causes a moment of mental hesitancy that I do not get from "remove"
@U01M742UT8F I don't expect any nils but there can definitely be empty strings in the vector, so identity won't cut it unfortunately... š e.g. ["Elvis" "has" "" "left" "the" nil "building"]
@alexmiller that's what I thought, generally I'm with @U11BV7MTK but in this case remove does sound more natural to me as well, thank you both š
str/blank?
to the rescue!
(def x {:a 1 :b 2})
How do I subsequently qualify this map to something like
#:foo {:a 1 :b 2}
an important thing to note is that the map is not qualified, that is just a syntax that can be used when all keys (or symbols) share the same namespace
the map is {:foo/a 1 :foo/b 2}
Good point. Is there any sugar to qualify each key in the map to the same namespace or do I need to reduce it?
there is no core function that can magically do this ( update-keys
is coming in 1.11 though) so you would need to transform the starting map into a target map
(reduce-kv #(assoc %1 (keyword "foo" (name %2)) %3) {} x)
is one option
Sounds like 1.11 has some nice stuff in it. Thanks as always @alexmiller.
This is something I still struggle with, how to represent as edn a mixed map using the literal for the namespace.
(def d {:blah/name "my blah name" :id 1})
This doesn't work and I am not sure why.
{#:blah{:name "my blah name"} :id 1}
well that particular outer map only has 3 elements in it
those two things are not the same - you've introduced a nesting level
#:blah{:name "my blah name" :_/id 1}
can be used for this
although I can pretty confidently say almost no one is even aware that exists
Hey team, Iām trying to convert a curl request, into a clj-http call:
curl '' \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'sec-ch-ua: "Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'sec-fetch-dest: document' \
-H 'accept-language: en-US,en;q=0.9,fr;q=0.8,ka;q=0.7' \
-H 'cookie: ajs_anonymous_id=...; notice_behavior=...; <redacted>' \
--compressed
Now the question is, how to get the cookie into a ClientCookie
I have the following in a file:
ajs_anonymous_id=...; notice_behavior=...; <redacted> converted to a ClientCookie.
Then, if I write:
(clj-http.cookies/decode-cookie (slurp (io/resource "mfp_cookie.txt")))
It only seems to ge the āfirst partā of the cookie (the ajs_anonymous_id
)
Does anyone know how I can get it to parse the whole thing?I mean you can more or less split on semicolon and then split each on the first =, taking into account that some cookie values aren't key=val
here's one I used for decoding cookies in an app
or it looks like you could split on ;
and pass that to the plural function? https://github.com/dakrone/clj-http/blob/3.12.1/src/clj_http/cookies.clj#L79-L83
is there parhaps a tool that'd auto suggest possible namespaces/ classes to import?
and methods of specific instance of object?
(interop with java libraries)
i can imagine chances of this existing being slim but i figured i'd ask
@filip.strajnar do you mean in the context of an editor/IDE? If so, I believe IntelliJ/Cursive does that and so does VS Code/Calva to some extent (with LSP support).
@filip.strajnar https://clojure-lsp.io/ has a really good support for requires/refers but not for imports/classes as we don't have support for java classes yet on clj-kondo, but it's on the radar
Check code actions: https://clojure-lsp.io/features/#code-actions
Thanks @corasaurus-hex! Worked like a charm. For future reference, hereās what I did:
(clj-http/get
(str " "
username "?from=" from-date-str "&to=" to-date-str)
{:throw-entire-message? true
:headers mfp-headers
:cookies (->> (-> (slurp (io/resource "mfp_cookie.txt"))
(string/split #";"))
(map cookies/decode-cookie))})

Can someone please tell me where exactly I should start to get my hands on clojure, I'm a beginner
Where you start is shaped by what you want to achieve. Some common steps include ā¢ set up clojure and run a repl ā¢ choose a Clojure aware editor ā¢ learn the basic syntax and start learning about common functions (https://clojuredocs.org/, https://practical.li/clojure/coding-challenges/4clojure/, http://exercism.io) ā¢ start working on projects / building apps and services Hopefully you find https://practical.li/clojure/ a useful resource to help you get started (its freely available) There are also 100+ hours of Clojure coding videos at https://practical.li/ , the https://www.youtube.com/playlist?list=PLpr9V-R8ZxiDB_KGrbliCsCUrmcBvdW16 and https://www.youtube.com/playlist?list=PLpr9V-R8ZxiClng6zv2wqIEd_tOQB7gKx videos are especially useful for beginners
@jabeen2699 Welcome! Are you a beginner to programming as a whole or just to Clojure? Also, are you on Windows or Linux/macOS?
Cool. So https://www.clojure.org/guides/getting_started should get you up and running with the basics.
And then https://www.clojure.org/guides/learn/syntax (linked from that page).
A lot of folks also recommend https://www.braveclojure.com/ but it introduces Emacs which can be a bit daunting (you can ignore the Emacs stuff if you have an alternative editor with Clojure integration).
What editor/IDE do you use today, and what language(s) are you normally working with?
You'll probably want to join the #cursive channel -- the maintainer of that IntelliJ plugin is very responsive, as are other users there.
@jabeen2699 , Iāve created an interactive guide for that. Would love to know if you think it does the job: https://calva.io/get-started-with-clojure/
the getting started repl in calva it's fantastic to get a feeling for the language š
sort of a loaded question, but should I use lein or the clojure cli tools? Does one offer some functionality that the other does not?
should use them for what ? :)
Really the main thing I guess is dependency management for me atm - not necessarily packaging
packaging is a bit more configuration and often a small script with clojure cli. But so are the lein based versions, they are just baked in for you and are very difficult to diagnose or change. It is nice when they just workā¢ but very annoying if their defaults about what to include in a jar arenāt what you need
Personally: lein
is batteries included for a lot of things, but the moment you try doing something a bit more complicated youāll usually start hitting walls. clj
has very little magic to it, which sometimes means doing a bit more work than its lein counterpart, but anything more difficult becomes far simpler.
I started with lein, and moved over because of this. But also note I moved over because I started doing things that didnāt need batteries included. As a beginner, either will serve you pretty well.