This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-27
Channels
- # aws (8)
- # beginners (172)
- # boot-dev (4)
- # cider (16)
- # cljs-dev (123)
- # cljsjs (4)
- # clojure (90)
- # clojure-brasil (3)
- # clojure-dev (7)
- # clojure-dusseldorf (1)
- # clojure-finland (1)
- # clojure-italy (59)
- # clojure-russia (3)
- # clojure-seattle (2)
- # clojure-seattle-old (1)
- # clojure-spec (40)
- # clojure-uk (28)
- # clojurescript (327)
- # clojurewerkz (3)
- # code-reviews (8)
- # cursive (4)
- # datomic (24)
- # editors (1)
- # emacs (19)
- # fulcro (147)
- # funcool (1)
- # graphql (1)
- # hoplon (34)
- # jobs-rus (1)
- # lein-figwheel (5)
- # leiningen (20)
- # luminus (14)
- # midje (1)
- # off-topic (8)
- # onyx (7)
- # parinfer (47)
- # pedestal (1)
- # perun (1)
- # portkey (46)
- # re-frame (25)
- # reagent (9)
- # remote-jobs (4)
- # ring-swagger (5)
- # rum (1)
- # shadow-cljs (113)
- # slack-help (8)
- # spacemacs (7)
- # sql (9)
- # tools-deps (23)
- # uncomplicate (3)
- # unrepl (3)
- # yada (6)
C++ has a great notion of destructors. I can create a "smart pointer" that points to an external resource, where the destructor releases the resource. Thus, when nothing points at the smart ptr, we auto release the resource. Is there anything like this in Clojure?
For Clojure on the JVM, I believe there are articles people have written about Java finalizers, which are intended to be run when a Java object is about to be garbage collected, that give all kinds of warnings and caveats about there being no guarantee such a thing will ever be called.
This Wikipedia page may contain mentions of most of the known issues: https://en.wikipedia.org/wiki/Finalizer
in C++ destructors are also either expressly invoked via delete or by the close of lexical scope. if that’s enough for you, you should be able to simulate that effect easily enough
i dont deal with java all that much but last I looked for a destructor-like mechanism people basically just added a “close” method by convension
i guess this just comes down to differences in garbage collection….c++ is really explicit about when that happens (which is, right now), whereas jvm it may be several minutes before destruction/deallocation of an object
or if you’re like that old newsgroup post and you’re writing flight control software for cruise missiles destruction happens in the most literal way possible
Let me expand my problem a bit more. Suppose we have:
(let [a1 (alloc some resources)
a2 (alloc some other resources)
a3 (allow yet more resources)
a4 (and more resources)]
...
)
now, any of these allocs may fail. If a3 fails, I need release to be called on a1 & a2.
I believe C++ scoping rules takes cares of this with regards to exceptions unwinding the stack. With Clojure, this seems like atleast four try-catch clauses.Depending on what the resources actually are, this is similar to 'with-open', except you don't want to close things when they leave the function's scope. It's also similar to the component/mount/integrant life-cycle ideas.
I think the idea can transfer to those. Are they cleaned up only in case of a failure to allocate? (well, and at the "proper" clean up time, too)
@foxlog I assume you mean it works when you execute it in the repl? I think the issue is that for
is lazy so it doesn’t execute any side effects. Stick a doall
around it
@foxlog Since you are executing updatewithchinese
purely for side effects and you do not need/use its value, you'd be better off using doseq
instead of for
.
(defn translate [from to]
(doseq [result (querywords from to)]
(updatewithchinese (Translate/translate (:words result)) (:words result))))
Well, you're printing them out in the order you see. The order of the (println ...) expressions is explicit.
Yeah, line 35 through line 37 are blocking calls. So (<!! c1) blocks until it retrieves it's value, and so on. One way around this is to use alts
if you know the execution time of each of those queries beforehand, you could try reordering your blocking calls programmatically
@benzap how about if I don’t know execution time? I mean let first finished first printed.
I have an interop call for a protobuf message that looks like this: (RxAPI1.Rxapi$ServerMsg/parseFrom msg)
and I'm trying to figure out if there is a way for me to type-hint msg
, as the reflection warning says call to static method parseFrom on RxAPI1.Rxapi$ServerMsg can't be resolved (argument types: RxAPI1.Rxapi$ServerMsg).
I created a #joker channel for scripting/linting in https://github.com/candid82/joker
In this case you should not use 3 channels, but only one. Have all queries write to the channel, then take 3 times from it, you will take the results in the order they were put in the channel.
Ah, now I see that the queries are not actually doing anything with the channels. If you want to do three queries then use the fastest, then you need to create three channels and use alts!
.
Is it possible to exclude some folders from ag search path in emacs? I also use projectile but .projectile file didn't help.
(import java.util.ArrayList)
( def cart (new ArrayList))
(.add cart "sugar")
(println cart )
#object[java.util.ArrayList 0x2db68f [sugar]]
Hi, everyone! I am new here, don't quite know how it works. I was looking for support on how to install the required resources for running anglican code in closure. I can't find useful documentation
*clojure
@black.franco.formicol you're talking about this: https://github.com/probprog/anglican - right? You need to install lein first: https://leiningen.org/
Then add [anglican "1.0.0"] to your project.clj file, then run lein repl
and follow their intro tutorial
I'll try that in an hour and let you know as now I can't, but thank you for your reply!
I don't know exactly where I should add [anglican "1.0.0"] to my project.clj file
is under :dependencies?
that row was :dependencies [[org.clojure/clojure "1.8.0"]]
shall I make it :dependencies [[org.clojure/clojure "1.8.0"] [anglican "1.0.0"]]
Hi, again! Sorry to bother, but I tried to follow the instructions on the paged linked but the link from which I should download using git doesn't work and I can't find any alternative tutorial
Sorry, I don't quite follow what you're talking about. What exactly you want to download using git?
@black.franco.formicol There is an anglican channel on slack, activity is rather low, but still: https://clojurians.slack.com/messages/C471VDS9L
Also, the official repo for anglican has moved to bibucket: https://bitbucket.org/probprog/anglican I assume that you have already seen the anglican website. Unfortunately, the page for the examples has been broken for a while, but I already created an issue and the developer said he is going to fix it. If you have further questions an using anglican, just post them on the channel or ask me directly.
(thanks in advance)
What is a "key function"? The term is being used in "Clojure for the Brave and True" book
@xjongar can you provide context of how it's being used?
@xjongar I think that book is on line, if you could link to the context that would be easier.
my first guess is it means using a keyword as a function
> If your sorting needs are more complicated, you can use sort-by, which allows you to apply a function (sometimes called a key function) to the elements of a sequence and use the values it returns to determine the sort order. I am confused about the difference between a key function and a normal one.
Oh it's just how it's used. Key means a function used to compare values, and originates from other Lisp's use of the term.
Common Lisp's sort function (and a lot of other functions) for example, accepts an optional "key" parameter, which is a function used to sort by, such as <, >, etc.
(sort [3 5 4])
==> [3 4 5]
clojure knows how to sort numerics
(sort [{:my-key 4} {:my-key 3}])
==> ClassCastException clojure.lang.PersistentArrayMap cannot be cast to java.lang.Comparable clojure.lang.Util.compare (Util.java:153)
Clojure doesn't know how to sort maps
(sort-by :my-key [{:my-key 4} {:my-key 3}])
==> ({:my-key 3} {:my-key 4})
I tell clojure to sort by running a function on each value, in this case :my-key
(which is the same as (fn [x] (get x :my-key)
), and use the resulting value to sort
I see, thanks for the clarifications. I started learning Clojure in the past few days and I am enjoy it so much 🙂
Is there something like clojure.data/diff that compares doubles with a tolerance?
(<= (Math/abs (- i j)) tol)
?
Sort of, but for all the values in two map structures
you could wrap diff and just remove the differences that were caused by a double delta < epsilon
(fancy-diff {:a {:b 3.14159265358979 :c 2}} {:a {:b 3.141592653589793}} tolerance) => [{:a {:c 2}} nil {...}]
@alexmiller probably will do that, just was hoping there was something already done, thanks
generally, trying to change the meaning of equality in Clojure turns out poorly
Yup, I just have some doubles coming from a network request that end up (Math/ulp the-lower-one)
in distance
Thanks for the source link, I didn't see it in clojuredocs when I looked
Have to catch a bus now, but this gets me more or less where I was looking to me 🙂
@xjongar Since you're new to Clojure, you'll find the folks in #beginners are super helpful! Everyone in there is either a beginner or someone who has "signed up" specifically to help beginners. And "Welcome to Clojure!" 🙂
Is it possible to resolve
and "call" a macro, in the same way that you would a function?
For a CLI program, I am expecting a symbol passed in, which points at a macro. I need to use this macro to run some code.
user=> (def arrow (resolve 'clojure.core/->))
#'user/arrow
user=> (eval `(~arrow {} (assoc 1 2)))
{1 2}