This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-20
Channels
- # beginners (94)
- # boot (8)
- # cider (21)
- # cljs-dev (3)
- # cljsjs (5)
- # cljsrn (10)
- # clojure (167)
- # clojure-italy (4)
- # clojure-norway (1)
- # clojure-russia (9)
- # clojure-spec (25)
- # clojure-uk (29)
- # clojurescript (20)
- # cursive (12)
- # datomic (55)
- # emacs (10)
- # fulcro (16)
- # graphql (1)
- # hoplon (18)
- # lein-figwheel (30)
- # off-topic (259)
- # onyx (8)
- # other-languages (13)
- # re-frame (1)
- # reagent (62)
- # ring (8)
- # ring-swagger (28)
- # shadow-cljs (187)
- # spacemacs (15)
- # specter (2)
- # testing (12)
- # tools-deps (38)
Hey, coming from the JS community and formatter like prettier https://github.com/prettier/prettier , is there like one formatter considered as a standard in clojure, so far I found clfmt https://github.com/weavejester/cljfmt
You can look for extensions to your editor like Parinfer which will auto indent/format code for you and manage parentheses. I use VSCode and use the Parinfer extension for that, but it's for many different editors. https://shaunlebron.github.io/parinfer/#editor-plugins
@U62LF4PT5 cljfmt
is pretty much the de facto standard I believe, as far as taking existing source code and reformatting it. There's a plugin for Leiningen to run cljfmt
on your code. As @U9A1RLFNV indicates tho', most Clojure-savvy editors will auto-format your code as you type it in.
And this is the community style guide that most everyone adheres to https://github.com/bbatsov/clojure-style-guide
Some of the things that are hard to get used to at first, coming from other languages, include not using {
.. }
block style indentation like C-family languages.
So we write
(defn foo
"My docstring"
[args]
(some-call args))
rather than (defn foo
"My docstring"
[args]
(some-call args)
)
for example.That’s prefectly fine to me ! I don’t have much opinion on styling, I was looking a formatting library for the sake of consistency, good I’ll look into it thanks !
Hi. I have seen someone using a keyword like that: :a/b/c
1. is it normal?
2. what is the semantic of a
, b
, c
?
I must admit, I was a bit surprised at just how permissive the reader is about keywords...
user=> :a//
:a//
user=> :a:b
:a:b
user=> :
:
I knew that the keyword
function accepted any string and produced keywords that you couldn't type in, but I was pretty surprised those three above are accepted by the reader! 🙂I saw it in a recent JEE conf in a talk about clojure. https://youtu.be/Svhhga9Rxnc?t=1448
Does the '/' in the keyword have only a conventional meaning or a real technical meaning? What other character we should use to replace it if we want to represent a kind of directory or tree in the keyword?
@vincent.cantin It has a technical meaning as well. It separates the two parts of the keyword - the namespace and the name. These are separately accessible through functions with those same names, and are provided as separate arguments to the keyword
function. If you want to have a namespace with deeper hierarchy, you should use "." separators like regular Clojure namespaces.
What is the internal representation of keywords, flat string or structure with a namepace and a local id?
They seems to be implemented as wrappers around symbols https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Keyword.java#L28
@michael.gaare you are right: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Symbol.java#L63
Are there any good libraries for testing external REST APIs? I could just use clojure.test with some generic http client, but I wonder if there are ergonomics/conciseness out there that I might be missing.
@relan https://clojure.org/community/resources#_tutorials_and_learning_materials
What you should choose really depends on your learning preferences and background
check this out http://vvvvalvalval.github.io/posts/2018-01-06-so-yeah-about-clojures-syntax.html
you’re defining the Var mylist
to be the list with elements 1, 2 and 3, and then mapping over it applying inc
over every argument
So to use two functions for the same data structure u use ; (first function second function data-structure)
the simple rule is to call a function, you start with a list, first argument is function that you want to call, followed by arguments (fn arg1 arg2)
the arguments depend on the function, in case of map [https://clojuredocs.org/clojure.core/map] first argument is function followed by a collection
Clojure is evaluated inside out, so to use two functions on the same data structure you do (second-fn (first-fn data-structure))
, which is like secondFn(firstFn(dataStructure))
in a c-like lang.
map
is a function that takes a function as its first argument and a collection as its second
i.e. are you calling a function for its side-effects or to transform some data to be used in a later fn?
are you looking for something like this?
(let [mylist '(1 2 3)
a (func-a mylist)
b (func-b mylist)]
.. use `a` and `b` here
)
and as @madstap mentioned if you don’t need to reference the value a
separately, you can do:
(let [mylist '(1 2 3)
b (func-b (func-a mylist))]
.. use `b` here
)
Btw..as per my understanding ..clojure has Own standard library + Clojar + java ecosystem ?
super late to the party but here's my 2c anyway: I love elixir's pattern matching support in functions (especially symbolic equality matching) and like clojure, it also supports macros (you can manipulate code as data structures). It's great if you want to play with the erlang OTP. However, the biggest advantage for Clojure is the libraries from both the Java and JS world.
Example of what I mean by symbolic equality, this function in elixir returns true if the 2 arguments are equal:
def equal(a,a), do: true
def equal(_,_), do: false
and since elixir supports applying fn without parens (for better or worse), you can actually write elixir in lispy syntax: (myFn foo, bar)
In case folks want to dig deep into non-Clojure languages, there's a #other-languages channel.
I have a large sequence of maps (with some nested values), for which most of the values are the same, and therefore uninteresting. i’d like to see the different values in the map.
so for the input:
[{:a 1, :b "something", :c "same"} {:a 1, :b "else", :c "same"}]
i’d like the output
[{:b ["something" "else"]}]
or something like that. that is, {:a 1}
and {:c "same"}
are dropped.there still might be a slightly hairy reduce - not sure if you can just diff each element to it's neighbor, or if you need something more advanced than that
clojure.data/diff works for comparing two arguments. yeah, is getting it to work on a seq of args as easy as (reduce clojure.data/diff my-seq)
?
(def a [{:a 1 :b "unique" :c "same"} {:a 1 :b "differe" :c "same"} {:a 1 :b "three" :c "same"}])
(clojure.data/diff (first a) (second a)) <-- works as intended
(reduce clojure.data/diff {} a) produces:
[[(nil {:a 1, :b "unique", :c "same"} nil) {:a 1, :b "differe", :c "same"} nil] {:a 1, :b "three", :c "same"} nil]
i don’t understand that.and when it compares the diff against the next map in the seq, they look competely different
i’ll have to keep thinking about this a little bit. thanks lilactown and sundarj for your help so far