This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-15
Channels
- # announcements (5)
- # architecture (17)
- # aws (2)
- # bangalore-clj (1)
- # beginners (157)
- # boot (22)
- # boot-dev (2)
- # cider (64)
- # clara (2)
- # cljs-dev (3)
- # clojure (30)
- # clojure-art (2)
- # clojure-australia (1)
- # clojure-belgium (1)
- # clojure-denver (1)
- # clojure-dusseldorf (1)
- # clojure-europe (8)
- # clojure-finland (2)
- # clojure-italy (9)
- # clojure-nl (21)
- # clojure-spec (261)
- # clojure-switzerland (3)
- # clojure-uk (67)
- # clojurescript (57)
- # clojurewerkz (2)
- # cursive (3)
- # datomic (27)
- # emacs (12)
- # figwheel-main (2)
- # fulcro (48)
- # garden (67)
- # graphql (41)
- # jobs (8)
- # kaocha (8)
- # liberator (2)
- # lumo (1)
- # off-topic (19)
- # parinfer (9)
- # perun (4)
- # re-frame (50)
- # reagent (7)
- # remote-jobs (4)
- # ring-swagger (20)
- # rum (6)
- # shadow-cljs (170)
- # specter (3)
- # tools-deps (19)
- # vim (3)
hey guys, can you tell me what i am doing wring here (swap! profiles apply assoc [id1 profile1 id2 profile2]))
? is it possible to do that?
@quieterkali assoc is variadic, so you can do:
(swap! profiles assoc id1 profile1 id2 profile2))
swap! and most core functions that resemble it (update-in, update, etc.) expand out to put the thing you’re swapping in between the function and the args
your swap! call used #(apply % assoc [id1 profile1 id2 profile2])
but the argument should have been #(apply assoc % [id1 profile1 id2 profile2])
unless you call swap like so: (swap! profiles #(apply assoc % [id1 profile1 id2 profile2]))
which is clumsy
(swap! profiles apply assoc [id1 profile1 id2 profile2]))
results in a function call like (apply @profiles assoc [id1 profile1 id2 profile2]))
which is of course, incorrect
you can use (apply swap! ..)
though
do you understand why (swap! profiles apply assoc [id1 profile1 id2 profile2]))
doesn't work?
swap! takes an atom, and a function, and some arguments, then atomically sets the value of the atom to (apply fun value-of-atom args)
(apply swap! profiles assoc id-list)
will work, as would (swap! profiles (partial apply assoc) id-list)
or the #() constructions suggested above
the lambda that ghadi suggested
like why is it getting passed a vector of [id profile id profile] and not a map of {id profile} or a vector of pairs [[id profile]]
when opening a project with cider and emacs, I often want to interactively work on functions... if dependencies/imports of my own code are in other files, I have to open all of those buffers and evaluate everything in them to avoid errors...
is there a way to evaluate everything? on a related note, can anyone explain to me what's going on here? when I run a project from the repl, it seems like everything is being evaled on launch... why/how is this different from opening a project and using cider to eval things?
> when I run a project from the repl, it seems like everything is being evaled on launch this isn't a built in clojure behavior, it's being done by a project-manager (eg. lein) config
you can do the same thing via (doto 'my.ns require in-ns)
(in a regular repl, I'd assume CIDER would accept this as well)
I'm sure there are good shortcuts for CIDER, probably more appropriate to ask in the #cider channel if you need more info specific to that tool
I use cider to connect to a running repl, btw.
Hello everyone: I would like to have a tread that updates a graph of incoming data over a web socket. Are there any good dynamic graphing libraries in Clojure that I can’t seem to find with google?
Hey. I was wondering if I'm doing something wrong with clojure.test
or it's error reporting is a bit ... weird. I have some test code:
(defn assert-pieces [game expected-pieces-repr]
(let [select-for-comparison (fn [piece] (dissoc piece :id)) ;; generating pieces creates unique ids
actual (->> game :pieces (vals) (map select-for-comparison))
expected (->> expected-pieces-repr (parser/parse-pieces) (vals) (map select-for-comparison))]
(is (= expected actual))))
When I break a test I get this:
expected: (= expected actual)
actual: (not
(=
({:size 1, :owner "p1", :location {:x 0, :y 0}, :orientation :up}
{:size 1, :owner "p1", :location {:x 1, :y 0}, :orientation :west})
()))
This seems really hard to parse. I'd expect expected
value to have been evaluated and printed out, but instead I get the original expression. Actual section has both actual
and expected variables
eval'd but it's still pretty hard to understand which is which without going back to read your assertions.actual
shows expected and actual in the order you use them in the test, so
expected: (= gt result)
actual: (not
(=
gt
result)
In your case, it expected:
({:size 1, :owner "p1", :location {:x 0, :y 0}, :orientation :up}
{:size 1, :owner "p1", :location {:x 1, :y 0}, :orientation :west})
but got ()
Seems pretty straightforward to me 😉
EDIT: renamed actual/expected to result/gt in order to avoid confusionI guess im just used to junit/scalatest where i'd get
expected: ({:size 1, :owner "p1", :location {:x 0, :y 0}, :orientation :up}
{:size 1, :owner "p1", :location {:x 1, :y 0}, :orientation :west})
actual: ()
I think the difference is clojure assertions don't always check for equality
So you don't necessarily have two expressions that should match. is
only checks whether a single expression is true. What that expression is comprised of is up to you
Does that make sense?
I have a instant time like this
#inst "2018-10-14T13:21:56.000-00:00"
whats the easiest way to get the hours,minutes and seconds like: "13:21:26"?i guess I can use clj-time here?
worked perfectly thank you 🙂
now i just need to regexp for the date 2018-10-14 but i'll manage. thanks again!
seems like it casts the time to my time.
converts it from utc to gmt+1
is it possible to grep a file from the shell in clj and get the result as text?
Sounds like something planck or lumo would be good for.
maybe a silly question, but how would I get to a var
(if it exists) from an arbitrary value..? eg, from a passed function
if you use -> it should work. some-> doesn't work because it does some nil checking under the hood
what would the function to extract that meta data from the collection of functions look like?
if you want to dinamically retrieve a var from a symbol, you use resolve
on the symbol
the mapping can't exist (unless you annotate the value with the original var, using metadata)
(def f [] "blala") (some-> f quote resolve meta :query) that is the code i tried in my repl
How much differences does Luminus and Re-frame? Do I need to learn Reframe to start learning Luminus?
Luminus helps you build pre-configured web applications, optionally including re-frame as a front-end component. You can start learning luminus before you start learning re-frame.
So, is ti possible and recommended if I build Rest API server with Luminus and building Rest API with Re-frame, in a single project?
*is it
Well, let me re-phrase that slightly just to make sure we both have the same understanding: You can use luminus to build a server-side REST API, and you can use re-frame to build a client-side user interface that communicates with the server-side REST API. Yes, you can do both in the same project.
Oh ya ya.. I got it. Thank you @manutter51
I was just curious about a namespace issue. if I'm in my clojure-noob.core file and have a repl connected, if I change my ns from user
to (ns clojure-noob)
then I seem to lose the ability to look up simple docs like (doc inc) or whatever. Do most people stay in the user ns?
and if I'm still in the user namespace but I load my buffer (in Cider) using C-c C-k then I still don't seem to have access to my created functions in the user namespace. I do have access to them if I manually send them to the repl like C-c M-p
that's because in-ns doesn't initialize your ns or load the requisite code
require or otherwise load the namespace from the file before switching to it
if you are creating an ns from scratch, use ns
instead of in-ns
loading a namespace doesn't make its vars available in your current ns - you can use require
with :as
to access the ns via a shorthand, or switch to that ns after loading it
if you mean the doc
function, you can run (use 'clojure.repl)
from the repl to access it again
your default repl starts with clojure.repl in scope via use, it also has clojure.pprint/pprint mapped to pprint
you need to set this up by hand in other namespaces if you need it
also, if you use in-ns
without creating the ns first, and everything seems broken, you can use (clojure.core/refer-clojure)
to get the default clojure.core functions back
I find that some experimentation with these functions in the repl should clear up how things work relatively quickly - after that you can also use the convenient shorthands that your editor provides and you'll actually understand what went wrong if one of the steps goes wrong
Does anyone know of a library which converts from EDN to JSON that won't hit a StackOverflowError with a deeply nested map? I've tried Cheshire and clojure.data.json but neither seem to support this. I suppose I'm looking for something which is tail recursive
Tail recursion for tree operations is tricky (you end up having to move work that was implicitly being done by stack operations into explicit data management in the heap), so I'm not surprised the standard libs don't implement this.
do you know how deep it goes? I know update-in
is recursive but not tail recursive. Be interesting if you can't update in it either
I think I may have just figured out that I don't need actually need that functionality anymore
I'm passing the response of a query to datomic to the json generator, and didn't consider that it may be evaluating a lot of nested relationships which I don't actually want - which is why the map is deeply nested
a gordian knot solution could build an adjacency list (effectively flattening a tree in a way that keeps all info needed to reconstruct the tree), and then do the reverse operation on the consuming side
but yeah, better yet just don't encode some data
eg. I wouldn't be surprised if datomic is able to feed you cyclic data, so eagerly consuming it would always blow up