This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-16
Channels
- # beginners (176)
- # boot (11)
- # cider (12)
- # cljs-dev (65)
- # cljsrn (54)
- # clojars (18)
- # clojure (195)
- # clojure-austin (1)
- # clojure-dev (2)
- # clojure-italy (8)
- # clojure-quebec (1)
- # clojure-russia (51)
- # clojure-serbia (3)
- # clojure-spec (24)
- # clojure-uk (28)
- # clojurescript (41)
- # cursive (14)
- # data-science (60)
- # datascript (2)
- # datomic (111)
- # emacs (6)
- # figwheel (1)
- # graphql (16)
- # hoplon (26)
- # juxt (2)
- # lein-figwheel (3)
- # lumo (12)
- # off-topic (8)
- # om (14)
- # pedestal (22)
- # perun (2)
- # proton (1)
- # re-frame (29)
- # reagent (27)
- # ring (17)
- # ring-swagger (2)
- # rum (3)
- # spacemacs (3)
- # unrepl (155)
- # untangled (28)
- # vim (4)
Getting this exception with Boot+Reagent on ClojureScript reload: Uncaught TypeError: goog.dom.htmlToDocumentFragment is not a function
I did some digging and found some things about an older version of cljs, but I can't tell if this is my bug or a weird dependency mixture issue.
Full exception:
Uncaught TypeError: goog.dom.htmlToDocumentFragment is not a function
at adzerk$boot_reload$display$construct_hud_node (display.cljs:93)
at adzerk$boot_reload$display$insert_container_BANG_ (display.cljs:104)
at display.cljs:126
at core.cljs:4311
at Function.cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2 (core.cljs:4311)
at cljs$core$swap_BANG_ (core.cljs:4304)
at adzerk$boot_reload$display$display (display.cljs:120)
at client.cljs:37
at cljs.core.MultiFn.G__11975__3 (core.cljs:10168)
at cljs.core.MultiFn.G__11975 [as call] (core.cljs:10277)
I have a hash map like: {"Number" "1", "Cluster" "M2"}
, I'm using map
on it like this: (map #(% "Cluster") my-map-data)
. There there any other ways better than #(% "Cluster")
?
@stardiviner Are you trying to get the value for the keys?
You can try (vals m)
In Clojure you can't modify the original map (or any "original" variable). What you want to try and do is make functions which you can plug into other functions to get the result you are looking for.
In this case, what should I do?
Are you trying to add the values of one map to another?
No, I created an empty map, then want to use a key as a number counter for counting how many times the character occurs.
Leaving for a while.
Yea, @dpsutton is correct. Use (frequencies m)
and that will get you your result. So (frequencies temp-collection)
will return {"A" 3, "B" 1, "C" 2, "D" 1}
What is the quickest way to test if any value in a sequence equals a number? Like in (or (= 5 (1 2 3 4 5)))
but this example doesn't work
Hi, I'm new to Clojure and I have a silly problem.
(defn currTime[]
(.format (new java.text.SimpleDateFormat "hh:mm") (java.util.Date.)))
(defn log[text]
(println (apply str [(currTime) " " text])))
(def awesomebutton (button :text "Sometext"))
(listen awesomebutton :action (fn [e] ((log "clicked!"))))
When clicking the button, the text prints but also causes a nullpointer exception
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
I've no idea what's wrong@vitruvia one way: (some #{num} '(num1 num2 num3 etc)) will return num if it's there
from http://stackoverflow.com/questions/3249334/test-whether-a-list-contains-a-specific-value-in-clojure
@sassafras thanks
okay this is silly, but I can't println
from one of my functions, even when it begins with a doall
I need that to debug one function the dirty way, even though usually I'd have tests to avoid the need in the first place.
if anyone uses a library that drops you into a repl from a line of code of your choice, that would be a nice replacement, but otherwise I wonder what might it potentially be with doall
not working for me.. and believe me this function gets called (verified that by replacing the println
with throwing an exception).
also by the docs of doall
(https://clojuredocs.org/clojure.core/doall) I'd assume that the println
would happen by the time my program finished, even if not right away.
I believe your issue is that str
doesn't force lazy sequences, which your filter
s are
@matan my favorite way to debug is (defonce debug (atom []))
at the top level, then (swap! debug conj {:context :some-context :a a :b b ... ...})
inside my function
that gives me actual data I can play with in my repl - including evidence of how many times the function has run
also, one of the things you could capture in the hash-map is *out*
- maybe something else is binding it weirdly?
Can you use a varible assigned with let to create a second variable? Like (let [a b c (* 2 a)])
@dpsutton I am using an exception to see what's going on (pretty silly). E.g. this works.
(throw (Exception. (str (row-examination (first (filter #(= (key (first %)) "19329") gold))
(first (filter #(= (key (first %)) "19329") test))))))
Not sure about your code snippetbut str
doesn't realize a lazy sequence. you should use clojure.string/join
to get all of them
what is the closest point to where one wants a side-effect to happen, that a doall
wrapper should be placed?
because i believe that doall will do what you expect it to except coerce lazy sequences of strings. so i want to see more concretely what you're doing
first thing, never return true if something and false if not something, just return the something
juxt does exactly what you were thinking there, distributing hand across the functions
(and (straight? hand) (flush? hand))
seems like a winner to me
it returns the right value, it’s easy to read
@dpsutton thanks but what is wrong with returning true
? The exercise asks me to return either true or false
what do straight? and flush? return?
I would assume by name they return true or false
if so, the and will also return true or false
@vitruvia the problem with (if true true false) and (if false true false) is both can just be replaced by the condition
it’s needlessly verbose - provides no meaning, and doesn’t change the result
@dpsutton I wrap my entire function with doall
the same one copied above, I can copy again
But this is only the case if the functions being called return true or false, right? As in the case of straight?
and flush?
matan, that function you pasted earlier didn't have balanced parens and i didn't a doall. just wondering if you could give me a complete picture
@vitruvia the accepted rule is that any function ending in ? should return true or false
which is why we assume the if is redundant
it’s possible to use boolean
to force a “truthy” or “falsey” result into a real true/false where that matters
,(map boolean [nil false true 1 :a])
the println
forms won't work regardless how I wrap with doall
.
I resort to keyhole debug by uncommenting the exception form.
(let [rows (doall (map row-examination gold test)) ...
is the one that seems to actually do work here
my general question is ― what is the most closest point where doall
wrapping should be performed, relative to where one wants to execute side-effects
i don't think that's a well-formed statement. doall
by its signature can only take a single collection. so point to where a collection is created in your code
mystery solved: I was using with-out-str
on the function that kicks off the rest of the functions cascade. my println
s ended in an output file.
(spit (io/file "output" "raw.edn") (with-out-str (pprint output)))
I did that to get EDN nicely printed to a file, using pprint
. Obviously that negates the ability to println
anywhere inside lazy collections that are evaluated in the lazy EDN collection this is printing. 🙈
@matan remember I suggested saving the value of *out*
to an atom? that would have revealed it
okay, digging this @noisesmith
for further safety, is there any API for doing what pprint is doing, as string building, without sending it to stdout like pprint does? resorting to with-out-str
seems like something I might wish to avoid.
pprint takes a “writer” arg
> (doc clojure.pprint/pprint)
-------------------------
clojure.pprint/pprint
([object] [object writer])
Pretty print object to the optional output writer. If the writer is not provided,
print the object to the currently bound value of *out*.
nil
so you can give it a StringWriter or whatever
peregrine.circle=> (def sw (java.io.StringWriter.))
#'peregrine.circle/sw
peregrine.circle=> (pprint {:a 0 :b 1 :c 2 :d 3} sw)
nil
peregrine.circle=> (str sw)
"{:a 0, :b 1, :c 2, :d 3}\n"
you can provide a stringwriter to spit, instead of a string, it just works
peregrine.circle=> (spit "foo.edn" sw)
nil
peregrine.circle=> (slurp "foo.edn")
"{:a 0, :b 1, :c 2, :d 3}\n"
@noisesmith for us slowbies, can you please give an example of how you then use debug
? my debug strategy is "sprinkle code liberally with (log/trace... ); season to taste." works but not so optimal.
@mobileink (-> debug deref count)
(-> debug deref peek keys)
(-> debug deref peek :foo type)
etc.
this is all done with up-arrow and editing the end of the line, of course
I very quickly get the info I want, then I can use it with the functions in the repl, fix my code, etc.
or even (-> debug deref (->> (map :foo) frequencies)) - to see all the data coming in in a bigger picture
good demo of the usefulness of threading macros - easy to throw another fn in the chain
exactly, it makes interactive exploration very easy
of course it can also help to do a (def foos *1) at some point
or whatever
to capture something of interest with the help of the repl
also, you can spit the data you captured in the debug atom somewhere into an edn file, and slurp it into a unit test 😄
I'm still not seeing the light on this debugging scheme, probably a couple of hours debugging with exceptions throwing, has taken its toll...
I mean, logging is still useful, I just find actually capturing the data useful when fixing something specific
@matan the idea is that if you capture the data as data, instead of (just?) printing, you can do smarter things with it, and the language can help you
instead of like trying to count parens to be sure what the structure is
I log for things that will be interesting whether I’m debugging something right now or not, but if I want to know what’s happening to data in a specific context, nothing beats being able to directly use the data in the repl
idle question: the sayid debugger guy was wondering why he's not getting more love. my theory: the repl plus techniques like this almost eliminate the need for a debugger. do you ever use a debugger? i never have for clojure.
> but if I want to know what’s happening to data in a specific context, nothing beats being able to directly use the data in the repl that sounds like there's a secret drop-to-repl macro to embed
@mobileink I tried, but due to some details about how clojure handles and clears locals etc. I find just being able to access the data and fiddle with it much more useful compared to stopping the world to interact with a breakpoint
@matan but I don’t want to stop the world - since my data is immutable I can just capture it and poke at it later
that debug atom trick really deserves a prominent place on the "Debugging Clojure Code" page.
I didn’t make it up, I forget where I learned it
someone shared it on IRC
oh, maybe you mean you usually don’t have a repl running when running your app?
yeah - I launch a socket repl, even on the server
and it’s actually very rare that I copy paste code into a repl on a remote server (if my boss asks, I officially never do that, haha)
@matan in dev I reload definitions usually
but really, my main repl interaction is trying out smaller pieces of what will eventually become my code - seeing what works or doesn’t work with the data at hand
like playing with playdoh
but you don’t need to inject anything
you capture it
the data is there if your app runs
you just save it for later
right, and I use spit to an edn file, and then I slurp and read from my unit test
I literally do this
I should make a lib that simplifies it (spit-to-test-data x) / (read-from-test-data x)
that would be cool
with like a config defaulting to “test/resources/” as a place to put the data
i hit the wal on my badassly wunnerful fix all probs lib about 2 months ago. now i just flap my jaws on clojurians until i can recover.
i mean it's easier to talk about code than to actually code, i guess. 16 hour coding days are wonderful, but only to a point. at some point you begin to want to chop your fingers off, so you offer some kind advice on clojurians, and gradually you recover and get back to work, heh.
try to pace it more balanced if you are not force labored into this 🙂 like it's North Korea
oddly enough by using a string writer with pprint
, every println
s evaluated while building output
still gets snatched into the string writer, I should dig into the source of pprint
oh yeah I just checked - pprint wraps its body in with-pretty-writer, and with-pretty-writer uses with-out-str
you could use a real logger 😄 - too bad that’s overcomplicated on the jvm