This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-05
Channels
- # bangalore-clj (2)
- # beginners (132)
- # boot (311)
- # cider (5)
- # cljs-dev (27)
- # cljsjs (2)
- # cljsrn (16)
- # clojure (76)
- # clojure-art (1)
- # clojure-france (8)
- # clojure-russia (35)
- # clojure-spain (3)
- # clojure-spec (2)
- # clojure-uk (11)
- # clojureindia (1)
- # clojurescript (98)
- # core-async (3)
- # css (9)
- # cursive (9)
- # datascript (7)
- # datomic (7)
- # emacs (30)
- # jobs (1)
- # lein-figwheel (7)
- # london-clojurians (1)
- # lumo (14)
- # off-topic (6)
- # om (1)
- # planck (3)
- # protorepl (1)
- # re-frame (27)
- # reagent (17)
- # spacemacs (10)
- # untangled (1)
- # yada (16)
Is there a Clojure function (fn f coll) which will return the first elements of the collection such that f is true, stopping when f is false? I.e., (fn #(<= 3 %) [1 2 3 2 1 4 5 6] would return [1 2 3 2]. Is there such a function?
https://www.conj.io/store/v1/org.clojure/clojure/1.8.0/clj/clojure.core/take-while @fadrian
i’m trying to transform a vector into a hashmap where the key is a function applied to the each value in the vector and the value of the hashmap is a vector of every value in the vector that has the same key
pgmcgee something like (group-by identity (map your-fn your-vector))
should do the trick
@eslachance To make it even cleaner you could use case
instead of cond
and then destructure to avoid the double str/split
.
I had this exact argument about case
vs cond
with my best friend. My argument was that I knew for a fact that some of these conditions (like the next one I was about to have) was based on 2 conditions. not one.
However, I am open to the destructuring - I haven't seen that in clojure yet!
https://github.com/datodev/dato <-- this looks very cool based on README, but based on git commits, last commit seems to be over a year ago -- is there a spiritual successor to this?
if i have a record in core.clj, how can i refer to that record type in test_core.clj when I require [core :as c] in the ns form?
The actual Java class has to be imported
(:import [core.MyRecord])
If you just need to create the class just use c/->MyRecord
it's actually an error in CIDER, but my suspicion is that the error happens below CIDER
Also note: the name you need to use via :import will be munged (see clojure.core/munge). So Foo-Bar! => Foo_Bar_BANG_
running all tests, one of which is asserting
(is (= test_record.core.MyRecord (type (map->MyRecord {}))))
lol, why is it doing that?
Yeah...that's a fairly useless test
after you re-eval the parent namesapce, the types will change, and you'd have to re-eval the test namespae and re-import
yeah, i figured the macro expansion would be pointing at older types even though they are the "same"
but i'm just trying to verify if that's actually a bug in the testrunner itself, because CIDER really just paints some testing info on top of whatever the code evaluates to
If the user is re-evaluating the defrecord, and not the test namespace, then I would say that this is unsupported behavior
The bug doesn't mention if the test ns is re-evaluated. But everytime you re-eval a defrecord it generates a new class. and that class will not work with any previous classes.
Well a great way to test this is to do it in a bare repl
nrepl, cider, etc. all add a lot of, stuff (for lack of a better word) that can mess up Clojure
If you download the clojure jar.
you can do java -jar clojure.jar
And that will give you a repl,
And if you then require the test namespaces
you can switch into the namespaces and run the tests manually (they are functions)
so you can either do clojure.test/run-tests to run all tests, or just call (a-test) to run it
files need to be on the classpath, then you can require them by namespace (require ‘my.namespace.tests)
What purpose does the name
argument to the anonymous function constructor (e.g. (fn myfun [_])
serve? Based on a reading of the fn
macro, it would appear that the name becomes metadata on the function. But it doesn’t! Why not?
Yep, I’ve done that one before too. But why (said in a whiny voice) isn’t it also metadata on the fn object?
Why would it be metadata? Do functions ever have their name as metadata
Now I understand the fn
macro better and can see why the above associates metadata with the anonymous function. Seems like an ideal place to associate the name as metadata as well though.
For what end though. It's not like these names are unique, or in some global registry.
There's also the class name that gives a semi unique name for any function
It would also impact closure creation performance, no?