This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-04
Channels
- # admin-announcements (3)
- # alda (4)
- # beginners (30)
- # boot (116)
- # cbus (5)
- # cider (20)
- # clara (10)
- # cljs-dev (12)
- # cljsjs (41)
- # cljsrn (9)
- # clojars (6)
- # clojure (131)
- # clojure-bangladesh (5)
- # clojure-colombia (2)
- # clojure-dev (9)
- # clojure-ireland (4)
- # clojure-japan (3)
- # clojure-norway (10)
- # clojure-poland (6)
- # clojure-russia (59)
- # clojure-sg (1)
- # clojurebridge (2)
- # clojurescript (76)
- # clojurewerkz (4)
- # css (6)
- # cursive (21)
- # data-science (24)
- # datomic (27)
- # emacs (9)
- # hoplon (68)
- # jobs (2)
- # jobs-rus (1)
- # ldnclj (10)
- # lein-figwheel (9)
- # leiningen (21)
- # off-topic (5)
- # om (232)
- # onyx (63)
- # parinfer (2)
- # proton (25)
- # re-frame (12)
- # reagent (39)
- # untangled (6)
- # yada (122)
how can I map over list of functions and apply each of them on a value, to avoid constructs like this:
(str "//" (.getHost cs) (get-port-str cs) (.getPath cs))
@ag you can't treat a Java interop methods as anonymous functions (unfortunately, I've wanted the same in the past)
@danielcompton: there's memfn
that works around that somewhat
Is it possible to define a multimethod as a (let...)
binding?
The purpose for doing so is that I need to invoke the <!
macro within the definition of a multimethod's method. So I'm trying to put the definition of this multimethod within a (go ...)
block. And I know that I can put a go
block within a let
statement. So if I could define a multimethod as a let binding
(wrapped inside a go block), I would safely be able to use <!
within the multimethod.
I don't know how I would go about it? I guess I would need to invoke an anonymous multimethod? So then I could go
(go (let [m (anonymous-defmulti ...)]
(defmethod m :default
;; ...
(<! ...))))
Does clojure have anonymous multimethods?
@george.w.singer: You can't, the problem is the go macro. It won't walk into function definitions since they have a potentially different execution context.
But I'd argue that you approach this problem incorrectly. Pass channels around and do your own go block in the defmethod
You're probably right
Basically: I'm trying to avoid a remote read function (within a parser) from returning channel values.
I'd like it to instead wait, pull the value of a channel, and return it to the client
(defmethod server-reader :default
[env key params]
{:value (fn-that-returns-chan)}) ;; <-I'd like to be able to just go (<! (fn-that-returns-chan)) so that the client doesn't have to deal with a channel.
Does that make sense?
@george.w.singer: Use the blocking <!!
I'm unable to since I'm using clojurescript on the backend targetting nodejs
Oh I remember, you're the "node guy" . Well in that case you'll have to deal with async hell all the way back to the response. I don't know node.js well enough so I doubt I can help you.
At least I don't have to wait 5 seconds for my clojure server to spin up every time I restart it. With node.js it's about 100 milliseconds. ...the down side is I only get one thread 😞
But when you DO restart it, by the time it's done, you'll be as old as Rich Hickey 😂
@george.w.singer: This is getting off-top: 1. The correct channel for this should be #C03S1L9DN . 2. I haven't restarted my REPL in a few days, no waiting 3. To address your problem: IIRC there is tons of async libraries in node.js land where you can "deal with" multiple async results to be merged together. I'd pass in some function (in env) that registers your async result. Then before you shoot off the response that async library should wait for all of the async tasks that are pending. Then somehow get the value out of the async result and actually do the response. I might be missing some details.
Sounds good.
If I have a clojure map m
which is {:a "a" :b "b" :c "c"}
, how can I generate a new map which has exactly the same keys as m
but passes each of the keys through a function f
? The output in this case would be {:a (f "a") :b (f "b") :c (f "c")}
Is this a general way to make this happen in clojure?
Is there*
@dm3: yes that's perfect
Hello everybody. I am from Java. Like lisp, SICP. Will be rewriting a small project in Clojure.//Moscow
I’ve got some code that just doesn’t feel right… https://gist.github.com/metamorph/e1eb70ae65f5451aeefc — I check an input hashmap for existence of an entry, if that’s true then I try to apply a regex to another entry and then finally create a new entry in the map. If any of these steps are falsy i want to return the input. Any suggestions?
@mbertheau: also (some? (#{3 8 920} n)) should work
Just curious how many people are actively using Clojure in a data science or machine learning role on a daily basis?
gnejs: cond-> sometime helps...but in your case I'd just factor out a get-func-class function
Or working in a data science or machine learning role, using a different language?
gnejs: I also sometime use something like (merge thing (when foo? {:x "x"}) (when bar? {:y "y" :z "z"}))
hmm.. that could be a suitable form.. return the input by default and explicitly decorate the result if “somecondition”.
This is the function with the equality check
(defn to-prof
[listt]
(let [head (first listt)]
(if (= head nil) ; equality check
0
(+ head (to-prof (rest listt))))))
This is the function without the equality check
(defn to-prof
[listt]
(let [head (first listt)]
(if head ; no equality check
0
(+ head (to-prof (rest listt))))))
@urbanslug: could you try that again with (nil? head)
@jethroksy: Give me a min:
@jethroksy: nil?
is the same as an equality check
102 > boot -d tulos/boot-criterium bench -g "'`cat slow.clj`" -l slow -Q -- bench -l fast -g "'`cat fast.clj`" -Q -- report -f table -O
| :benchmark/goal | :mean | :variance | :upper-q | :lower-q | :evaluation-count | :outlier-effect |
|-----------------+-------------+------------+-------------+-------------+-------------------+-----------------|
| fast | 201.6449 ns | 24.3393 ns | 239.6927 ns | 179.9124 ns | 3336420 | :moderate |
| slow | 171.7123 ns | 43.9129 ns | 244.3292 ns | 142.8573 ns | 4134948 | :severe |
dm3: I don't quite get it and which profiling tool is that? I'm new to clojure all I can tell is that you're using a lib called boot-criterium
well, my comment is regarding the snippet you pasted as the 'fast' case. The snippet doesn't do the same work that the 'slow' case does.
and the bench result that I pasted is using boot
together with bench
and report
tasks from tulos/boot-criterium
@dm3: So in the first one it resolves the =
then head and applies =
to head
. In the second one it doesn't call the =
it resolves head to a value and if to it just checks if it's nil and short circuits. Am I right?
I posted this on #C053K90BR, but it seems rather un-occupied... heh: Hello. I'm relatively new to boot and am just trying to create a (pure clojure - no cljs) project that uses 'watch' and recompiles when I change a file in my source-paths. [17:09] I have these tasks: (deftask bundle [] (comp (speak) (aot) (pom) (uber) (jar))) (deftask dev [] (comp (watch) (repl) (bundle))) [17:10] When I change a file, I get Could not locate james/imbibe__init.class or james/imbibe.clj on classpath. (after i edit imbibe.clj) [17:11] Killing boot and executing 'boot dev' once again takes forever to restart (building the uber?). What is the best way to do this? [17:11] Thanks...
Is it only possible to call deftest`` and have it work properly in top level forms - and why?
deftest
I wanted to create a number of deftests following a similar pattern, but when I do eg (defn new-test [name arg1 arg2 arg3] (deftest name (is (= arg1 (+ arg2 arg3)))))
, I get a compile exception
a NullPointerException
As an attempt to get close to what I want, I've insted done (defn add-test [arg 1 arg2 arg3] (is (= arg1 (+ arg2 arg3))))
and then called it with (deftest two-and-four (add-test 6 4 2))
, (deftest seven-and-ten (add-test 17 7 10))
and so forth
Try to ignore the silliness of the examples
hmm, https://conj.io/ was my favorite go-to place for searching documentation but a few weeks ago its layout changed and now it’s unusable for me
could you suggest any other place where searching clojure docs would be more pleasant than on https://clojure.github.io/clojure/?
hm, a bit better. typing set
gives me a link to clojure.set docs. http://conj.io displays list of methods from clojure.core only
i liked old http://conj.io where i could search but also see a list of all functions on main page
is there a way to run a test fixture once for all namespaces being tested?
like with (run-all-tests)
AFAIK use-fixtures with :once is for each namespace
@jan.zy: sorry you feel that way, there's a ticket tracking this if you have comment to add. https://github.com/clojure-grimoire/grimoire/issues/231
How do I install Cider 0.10? I downloaded 0.10 and don't know where to put it. Most everything I install with elpa
i did make and it did a bunch of stuff but don't know where to put the dir and there is no elpa