This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-11
Channels
- # adventofcode (7)
- # aws-lambda (1)
- # beginners (161)
- # cider (19)
- # cljsjs (5)
- # cljsrn (30)
- # clojure (80)
- # clojure-korea (2)
- # clojure-new-zealand (8)
- # clojure-russia (73)
- # clojure-sanfrancisco (1)
- # clojure-spec (14)
- # clojure-uk (12)
- # clojurescript (84)
- # cursive (7)
- # defnpodcast (8)
- # dirac (16)
- # events (2)
- # garden (7)
- # hoplon (178)
- # off-topic (2)
- # om (58)
- # om-next (2)
- # onyx (21)
- # pedestal (1)
- # planck (15)
- # protorepl (32)
- # re-frame (31)
- # untangled (1)
- # yada (5)
Hey all, I have some code that’s similar to:
(Thread.
(fn [] (let [a (agent nil)]
(println “beginning”)
(dorun
(map-indexed
(fn [i _]
(println "About to send”)
(send-off a (fn [_]
(println “success”)))
(range 0 10))
(println "finished mapindexed”)))
but “success” never gets printed - everything else doesanyone used lein checkouts ? my project only works with them if I dont put their deps in the project.clj deps vector
but then it wont compile in clojurescript
only works in a clojure repl
@bronsa As you can see in my immaculately-formatted gist there, I’m taking one argument 😉
(doto
(Thread.
(fn [] (let [a (agent nil)]
(println "beginning")
(dorun (map-indexed (fn [i _]
(println "About to send")
(send-off a (fn [_] (println "success"))))
(range 0 10)))
(println "finished mapindexed"))))
(.start))
Hello clojurians! If any of you need additional help/support this holiday season feel free to shoot me a message, I am donating my time as a gift 🎁 https://medium.com/degree9/pre-clojureremote-17-year-end-cleanup-e829757a1f89?source=linkShare-a2d5aa46d2e3-1481424862
can I make pprint break lines after every key/value pair and disregard the width limits?
actually what I want to do is write an indented edn but the default indentation I get with pprint is a bit messy
and I'd like something like this: https://gist.github.com/spacepluk/1cbe7f43ac9d3aec1c25b9897b3c1cce
@spacepluk for more powerful pprinting, try https://github.com/kkinnear/zprint
question - why when I comment out or remove last line, second-to-last line stop working?
(let [uri "datomic:"]
(d/create-database uri)
(doto (d/connect uri)
((fn [db] (->> (fs/glob "resources/datomic-migrations/*.edn")
sort
(map #(-> % str (clojure.string/split #"resources/") last
conformity/read-resource))
(map #(conformity/ensure-conforms db %))
(#(doto % prn)))))))
@leov your intent is to print out the result of ensure-conforms
?
ok, wait one
last line appeared during debugging. when I add it - it works. when I remove it - it doesn't execute ensure-conforms
a faithful rewrite of your code, in (my personal take on) idiomatic Clojure:
the essence of it is that you use let
to grab conn
, do a side-effecting action with doseq
, and then return conn
. the rest is just my OCD 🤓
doto
is designed for use with mutable interop interactions http://clojure.org/reference/java_interop
Datomic connections are not mutable objects for you to invoke methods on
your actual question’s answer is that map is lazy
and prn is “realising" the collection produced by map
catches us all 🙂
it’s typically a smell to be using doto
outside of interop (e.g. java things), or wrapping function declarations directly inside invocations (such as ((fn [] …))
or (#(…))
)
that’s right. prn is eager. you could replace your prn line with a simple doall
as well
well, I'm just trying to inline as much unnecessary fun defs as possible, and trying to have Object#tap and Object#try after ruby...
turns out that’s actually an anti-pattern. for performance and for easy code reading a month from now
lots of little single purpose functions is best
https://www.youtube.com/watch?v=0tUrbf6Uzu8 for the performance angle
well, I can't agree just now, but yes, smaller functions are self-documenting by their name, with that I agree
you’re right, doto is tap-like
glad you’re on the journey. it’s lots of fun!
(thanks Google)
@leov the gist? Imagine a cons cell of "first" and "next", now make "next" a function with no arguments. Now memoize that function...that's about it.
So instead of a list being (:a (:b (:c, nil))) we now have (:a (fn [] (:b (fn [] (:c, nil)))))
technically so does next
, but you don't have to think about that half the time
lots of whole-sequence functions do too, of course; count
, doseq
, run!
, doall
, dorun
, reduce
, last
...
but those are all calling first
somewhere presumably
hello everyone! 😄 does anyone know a good GUI library for clojure other than seesaw? I need to make an executable program that allows the user to input simple commands and display the data
probably electron 🙂 https://github.com/Gonzih/cljs-electron ?
@rmuslimov thanks 😄 i’ll try that
@iecya if you want something that's on the JVM look at fn-fx: https://github.com/halgari/fn-fx/blob/master/examples/getting_started/02_form.clj
@tbaldridge thanks a lot 😄