This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-30
Channels
- # ai (3)
- # beginners (86)
- # boot (3)
- # chestnut (1)
- # cider (29)
- # clara (2)
- # cljs-dev (18)
- # cljsrn (1)
- # clojure (104)
- # clojure-greece (3)
- # clojure-losangeles (1)
- # clojure-spec (2)
- # clojure-uk (1)
- # clojurescript (5)
- # core-async (5)
- # css (3)
- # emacs (3)
- # figwheel (7)
- # fulcro (60)
- # lein-figwheel (3)
- # luminus (4)
- # off-topic (7)
- # portkey (14)
- # reagent (12)
- # rum (1)
- # shadow-cljs (9)
QUESTION: Anyway I can try catch a let binding, and have access to the bindings in my catch?
nothing simple, no
right, that's not even going to compile
in some weird cases I've had positive results with binding delays in a let block, forcing the delays in a try, and then checking if they are realized and conditionally accessing them in the catch
but you want to be careful you aren't forcing delays that didn't run yet in the catch block of course so it's clumsy
I'm thinking to just let a bunch of atoms, and inside the let do some weird side effect Java style assignments
(let [a (delay (foo))
b (delay (bar @a))]
(try @b
(catch Exception e
(when (realized? b)
...))))
you don't need atoms if you are only assigning once
Just because I want to log some of the bound vars inside the let in the case something throws an exception lol
a delay with a body that throws an error when forced throws the exception when forced - the reason to have the delay is so that a and b are in scope in the catch
oh, wait, sadly it doesn't work out that way
+user=> (let [d (delay (/ 1 0))]
(try @d
(catch Exception _)))
nil
+user=> (let [d (delay (/ 1 0))]
(try @d
(catch Exception _
(when (realized? d)
@d))))
ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:158)
or promise/deliver
+user=> (let [p (promise)]
(try (deliver p (/ 1 0))
(catch Exception _
(when (realized? p)
@p))))
nil
so you can guard usage of p in the catch block based on whether it's realized
it's too bad you can't do that with delays though
Hum, that's almost the same as making p an atom, but its a bit more explicit in the semantics I guess
it's a less powerful construct (and performs better)
it's throwing on deref, but it shows as realized
similar to the behavior of future - if it sees an exception it throws on deref
the exception means that deliver never gets called
similar to (println "error" (/ 1 0))
- "error" won't print, the exception prevents println from being called
I'm having an issue loading my core.clj
. It depends on a .clj file in the same directory but it says it's not found on the classpath. The directory is on the classpath though. The weird thing is if I load-file
on the depended upon file that runs fine, and after that I can also load-file
on the core.clj
without issues.
I suspect I messed up namespacing/directory structure or something in the project.clj. https://github.com/bbss/cljsc2/tree/master/src/cljsc2/clj
https://gist.github.com/hkjels/5637e59933d4c8cebf73d4052d75b2f8 Hi, I wrote this a while back and now I’m having a hard time understanding my own code 😒 Do any of you see where this short-circuits? What I would like is for all of the matches to be returned
I’m not certain yet, but I think there might be a performance-issue here as well, so if there’s a more idiomatic way of doing this, that would be great!
@bbss lein run
returns No :main namespace specified in project.clj.
Perhaps adding the :main
key and value will do the trick for you. You can run lein sample
for an example.
Oh, I don’t see a main fn in core. My suggestion probably won’t help. :thinking_face:
@jaymartin thanks, good suggestion to try anyway.
The other that might help is to use a tool like lein-ns-dep-graph to autogenerate a pic of your internal namespaces, and compare the generated image with your understanding of what should be. https://github.com/hilverd/lein-ns-dep-graph
@bbss FWIW, i’m getting the same error msg when running (load "cljsc2.clj.core")
from user ns at repl:
FileNotFoundException Could not locate cljsc2.clj.core__init.class or cljsc2.clj.core.clj on classpath. clojure.lang.RT.load (RT.java:458)
I'm willing to sacrifice pixel equivalency across platforms. Is there something faster than Graphics2D/bufferedImage for drawing text / rectangles / ovals ?
@qqq not sure, but you might poke around http://thi.ng/ because I know the author is into performance and well versed in such things.
@jaymartin: I have lost track of the # of times I have tried (but failed) to get into that librry
it's clearly brilliant; I just can't seem to find a tutorial/docs for "how to create an image+ render text with http://thi.ng"
Is there a straightforward way to turn a simple namespace (containing only defs and defns) into a map?
@jaymartin you mean clojure.tools.namespace/dir
?
Interesting. I recall namespaces themselves being maps. It might be useful to dig into Clojure source for this one and see if its somethings that is or can be coerced to a map.
@jaymartin thank you, I was hoping for a simple function but if I have to dive, I will 🙂
@pbaille You probably want to look at clojure.core/ns-interns
or clojure.core/ns-publics
something like (ns-publics 'clojure.core)
, for example, should get you all the public vars in that namespace
With a little bit of convolution you can get all the docstrings and other fun stuff out of a namespace
Actually, I just remembered I have the code around here: https://github.com/lsenjov/clj-slackbot/blob/master/src/clj_slackbot/evaluator.clj#L118
Never mind. I think the source of starvation/suppression is not clojure.core.async/mix
itself. Rather, how the data producers compete for another shared resource and wait for some fixed interval before trying again. Randomizing the interval seems to improve the situation.
@qqq I’ll be interested to hear what you decide on. Google turns up the usual mix of OpenGL bindings, game engines, and some stackoverflow commentary on how to optimize use of the standard java 2d libs. Are you rendering offscreen? Or is this onscreen visualization of some sort? Again, I’m just curious.
Need some macro help. I’m trying to walk a form and get meta data for each symbol.
(defmacro meta-sym [sym]
`(if (symbol? ‘sym) (-> ‘sym resolve meta) {}))
But (clojure.walk/postwalk #(println (ex/meta-sym %)) (read-string (clojure.repl/source-fn ‘max))) just prints out a bunch of nils
However, I can do (meta-sym defn)
and get a full meta map
Think I need @noisesmith and @bronsafor this one
@chalcidfly postwalk
and friends replace the nodes with the return values of your fn.
So would (clojure.walk/postwalk #(do (println (ex/meta-sym %)) (identity %)) (read-string (clojure.repl/source-fn 'max)))
work?
Note the do block that returns the identity
Now it’s printing a bunch of {}
. (symbol? ‘~sym) is return false on all of them.
This seems to work (I only have my iPhone with Replete to do this on though, sorry):
(def a {:foo ^{:test1 123} [] :bar (quote ^{:test2 456} baz)})
(clojure.walk/postwalk #(do (when (symbol? %) (println (meta %))) %) a)
@chrisjd thanks a bunch, looks like the issue was with the data structure I was trying to walk
I was trying to do it with (def a (read-string (clojure.repl/source-fn ‘max)))
Some months ago, I think that @alexmiller gave me a super-useful pointer on how to list all clojure data structures which implement some interface (eg clojure.lang.Associative
). I thought I made a note of it at the time, but damned if I can find it, and of course it's long since fallen off the cliff at the end of Clojurians' history. Anyone happen to know offhand how you could do that?
is this the discussion? https://clojurians-log.clojureverse.org/datomic/2016-12-22.html
Dang, @lgouger, nice find! Turns out it's exactly backward from what I remembered -- not a way to show all data structures which implement some interface, but a way to show all interfaces implemented by a particular data structure (namely (supers (class entity))
). So doesn't solve my immediate problem, but definitely goes into my notes this time.