This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-12
Channels
- # announcements (2)
- # beginners (104)
- # cider (2)
- # cljs-dev (26)
- # cljsrn (1)
- # clojure (125)
- # clojure-dev (27)
- # clojure-italy (24)
- # clojure-nl (24)
- # clojure-russia (4)
- # clojure-spec (10)
- # clojure-uk (83)
- # clojurescript (18)
- # code-reviews (102)
- # community-development (14)
- # core-async (18)
- # cryogen (11)
- # cursive (15)
- # datomic (16)
- # emacs (6)
- # figwheel-main (6)
- # fulcro (142)
- # graphql (5)
- # jobs (5)
- # jobs-discuss (18)
- # kaocha (1)
- # keechma (1)
- # leiningen (20)
- # luminus (1)
- # mount (5)
- # pedestal (4)
- # reagent (17)
- # reitit (8)
- # shadow-cljs (29)
- # tools-deps (19)
- # vim (108)
many thanks @didibus I still want to get to the bottom of the general rule of whether to mutate/decorate the original object argument or to return a new object with key references to components of the original object argument
I'm not sure what to make of it. I was expected fooBB to be faster and my questioning was "by how much". I have always thought that instantiating a new object is always more expensive than just editing the properties of an existing object
Unclear, when I look at the code, they actually seem kinda similar. Since there's only 3 elements in the map. It is a PersistentArrayMap under the hood. Get only does an indexOf and returns the array element. And then {} calls createAsIfByAssoc. While update just calls get, which should be the same performance. And then calls assoc. Which is pretty similar the createAsIfByAssoc. But I'm guessing there might be some minute difference.
Only difference I can see is assoc calls clone, while createAsIfByAssoc does a loop to copy over the data on its own.
Note that with Clojure's immutable collections, 'editing the properties of an existing object' is actually 'creating a new object that shares hopefully most of the contents of the original, but it depends on the editing you are doing'
When the operation is done, the original and the 'modified' versions are both accessible and usable in your code. Nothing has been modified in place.
Any good articles or books on application Design and architectures in clojure and functional languages in general.
@U1CUUKHDL A really good one although quite short and focused mostly on polymorphic aspects is https://leanpub.com/clojurepolymorphism
Thanks for the suggestions
@mcferren I think I figured it out. fooAA creates a single map. So it gets 3 values out of the map, increment, and then creates one new map with the new values. fooBB will get one key of the map, increment it, and then create an intermediate map with only the first key updated. Then, from this map, it will grab the second key, and increment that, and create anther map, etc. So in the end, it has to create 3 maps, while fooAA only has to create one.
Other variants that might be faster:
Rely on bar
being reducible:
(defn fooCC [bar]
(reduce-kv (fn [m k v] (assoc m k (inc v))) {} bar))
Same, but make the accumulator transient:
(defn fooCC' [bar]
(persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) bar)))
Employ a transducer (which should involve a transient accumulator):
(defn fooDD [bar]
(into {} (map (fn [e] [(key e) (inc (val e))])) bar))
From my bench reduce-kv is fastest. The transient versions don't seem to make a difference, and are even a bit slower. But, that was tested on a small map with a lot of iterations. I suspect the transient versions would start winning if the map was larger.
Yup, confirmed. Is the map is bigger, the transient versions start to perform better then the non transient versions.
What is a correct way of spiting the clojure map to .edn file with indentation of 2?
This is what I got so far
(with-open [writer ( "report.edn")]
(clojure.pprint/pprint inserts-map writer)
(println "Exiting...")))
The problem with this approach is that the data is truncated.It’s not an issue in a repl. Rather the pprint truncates the data i think. I’m using cider
pprint uses the default values of *print-length*
and *print-level*
, so if you set those to nil in your namespace you should be good: https://clojure.github.io/clojure/clojure.pprint-api.html#clojure.pprint/write
Thank you @U3L6TFEJF ❤️ You were totally right 🙂
hey guys, I am looking for an SSE (Server Sent Events) Client library (like gniazdo for websockets) do you guys have any suggestion ?
Are there any open source Clojure libraries that you consider excellent examples of using the language that you would recommend reading through?
@tkjone I have found browsing through anything by James Reeves (weavejester) really useful https://github.com/weavejester
@tkjone the code of https://github.com/metabase/toucan is annotated: https://rawgit.com/metabase/toucan/master/docs/uberdoc.html Very readable!
Hello gentlemen
Im new to clojure...
A bit of python and ruby experience ..and a bit of java.
Nice to meet ya'all
Hey @surya.malloc, live long and prosper!
Is there an easy way to change a leiningen project name and recursively change all it’s namespaces names?
@jarvinenemil gracias !
pablore I think you could check out if https://github.com/clojure-emacs/clj-refactor.el have some support for that. Else I think you have to go full bash mode.
Guys...how should i learn clojure....i mean how to get cozy with ()
http://www.agilelearner.com has a good course
Google clojure for the brave
Search for jr0cket
GitHub modern cljs
Start with installing spacemacs
IM me if you need help with set up or writing hello world
Read through the official Reference and Guides at http://clojure.org
Go through the exercises at http://4clojure.org
I had a good time learning Clojure with the materials for Clojurebridge. Especially the material that uses Quil for a lot of interactive "hello square" "hello circle" examples. https://github.com/ClojureBridge/curriculum
I'd done this type of algorithmic drawing in other programming languages, so it was learning a new language in a domain I already knew.
This is my first lisp lang
And im very excited
my suggestion is https://www.braveclojure.com/clojure-for-the-brave-and-true/ since you have experience in programming already
Splitting up code that runs inside Core.Async go-blocks -> Seperate things in their own functions and write tests for thoose functions?
How's clojure for gui
It can be as good as Java’s. https://github.com/Renanse/Ardor3D
Take a look at Clojurescript, https://clojurescript.org/about/rationale also there is: https://reagent-project.github.io/ (React for CLJS) https://github.com/Day8/re-frame (A opinionated "Reagent" for CLJS(?) I like it.) https://github.com/tonsky/rum https://github.com/omcljs/om etc.... If you want desktop-gui you can use re-frame with re-com and wrap it in electron, or use some java lib, think there are some clj-libs as well for that.
JavaFx and swing ?
Did you try clojure Seesaw?
You can use those. But its best to use them with interop. That is, doing java fx in Clojure will feel pretty similar to doing it in java.
how do I read a list of files from a given directory? I have http://clojure.java.io pointed at a directory, when I evaluate it, it's a
#object[infinite_carers_checklist.core$cp_files 0x15a04efb "infinite_carers_checklist.core$cp_files@15a04efb"]
how do I go from that to something I can iterate on?That looks like an fn generated inside cp-files
yep that was my issue 🙂
Hey Guys! I'm very new and I've started by going through a few tutorials and walk-throughs right now I'm working on https://www.demystifyfp.com/clojure/blog/restful-crud-apis-using-compojure-api-and-toucan-part-1/ and I'm having trouble connecting to the DB. I'm on Manjaro and I have postgres up and running on localhost:5432
with the db and user existing and having the right permissions (I can psql in).
(def db-spec
{:dbtype "postgres"
:dbname "restful-crud"
:user "postgres"
:password "postgres"})
(defn -main
[& args]
(models/set-root-namespace! 'restful-crud.models)
(db/set-default-db-connection! db-spec)
(run-jetty app {:port 3000}))
Gives me an error with a caused by that says
Caused by: java.lang.Exception: DB is not set up. Make sure to call set-default-db-connection! or bind *db-connection*.
at toucan.db$connection.invokeStatic(db.clj:124)
at toucan.db$connection.invoke(db.clj:117)
at toucan.db$query.invokeStatic(db.clj:275)
at toucan.db$query.doInvoke(db.clj:271)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at toucan.db$simple_select.invokeStatic(db.clj:379)
at toucan.db$simple_select.invoke(db.clj:368)
at toucan.db$select.invokeStatic(db.clj:641)
at toucan.db$select.doInvoke(db.clj:635)
I've tried a few of the other arg map values suggested in the toucan guide but same error
@btenggren20 That looks like a very old-fashioned way to interact with a DB (using mutable global state for the connection) so I'm surprised that's a recent blog post....
...Ah, Toucan is trying to imitate an ORM...
...I don't think that's a good approach, to be honest. Toucan doesn't look very idiomatic 😞
People use c3p0 or HikariCP for connection pooling mainly. The clojure.java.jdbc
docs have an example of the former http://clojure-doc.org/articles/ecosystem/java_jdbc/reusing_connections.html
org.clojure/java.jdbc
(aka clojure.java.jdbc
) is the "standard" JDBC library in Clojure (it's a Contrib library and it's the basis of pretty much everything else built around databases, including Toucan, which in turn seems to be based on / inspired by Korma).
Well alright! I'll give up on this. Although I did manage to make the connections work through the Repl
Its just like good ol’ IRC
JVM noob here: Would highly appreciate if you could point me how to get rid of it during compilation?
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
you need to add some version of sl4j to your deps, or change something else so nobody is trying to use it
logging in java is a bit precious
I’m trying to use exclusions like so:
[com.github.javafaker/javafaker "0.16"
:exclusions
[org.slf4j/slf4j-api
org.slf4j/slf4j-log4j12
log4j/log4j
org.slf4j/slf4j-simple]]
but it does not work at all 😞that's the opposite of what you need
you need to make sure some implementation is actually present
(or purge all the libs that try to use it)
Ok got it
It’s very bizarre that I have to include some logging library to just make the compilation silent.
it's because the logging design in java is a mess
it's not part of the core language, and there were multiple competing implementations, and weird decisions made about how to compromise on this so libs can do logging
I’m shocked
Will definitely read it @noisesmith. Thank you very much 🙂 I’ve added the slf4j and it’s working perfect 🙂 Btw where do Java guys search for the packages? I know that there is maven but is there something cleaner/with-examples/with-description like on npm website 😄?
Do you still recommend http://www.4clojure.com for learning? I'm bothered by the fact that I don't see clean code in the solutions.. I'm going through the exercises and looking for other's solutions to learn better approachs and more about the most used functions. What is bothering me is that I'm following a lot of people and I don't see mantainable code; code that one would commit in production; that's simple, easy and fast to understand. I see that the site value more the small code (code golf) than readablility. So I would like to know good references and examples of Clean Clojure Code, it would be perfect if you know some user with solutions like that.