Fork me on GitHub
#clojure
<
2017-02-05
>
schmee00:02:53

that’s clojure for ya!

fadrian00:02:07

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?

fadrian00:02:48

And [1 2 3 2 4 5 6 3] would still return [1 2 3 2]

fadrian00:02:29

Thanks. I just found it.

pgmcgee02:02:19

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

pgmcgee02:02:40

i’m having trouble figuring out an idiomatic way to do that

pgmcgee02:02:48

it seems like it should be a common problem...

schmee02:02:05

pgmcgee something like (group-by identity (map your-fn your-vector)) should do the trick

schmee02:02:33

no wait, misread

pgmcgee02:02:42

schmee: i think that’s exactly what i was looking for

pgmcgee02:02:59

yep, that should do the trick

radon04:02:11

@eslachance To make it even cleaner you could use case instead of cond and then destructure to avoid the double str/split.

eslachance04:02:01

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.

eslachance04:02:16

However, I am open to the destructuring - I haven't seen that in clojure yet!

qqq05:02:37

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?

dpsutton15:02:01

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?

dpsutton15:02:23

it seems its not c.MyRecord nor c/MyRecord

tbaldridge15:02:59

The actual Java class has to be imported

tbaldridge15:02:14

(:import [core.MyRecord])

dpsutton15:02:19

ah thanks much

tbaldridge15:02:28

If you just need to create the class just use c/->MyRecord

dpsutton15:02:47

it's actually an error in CIDER, but my suspicion is that the error happens below CIDER

tbaldridge15:02:28

Also note: the name you need to use via :import will be munged (see clojure.core/munge). So Foo-Bar! => Foo_Bar_BANG_

dpsutton15:02:37

running all tests, one of which is asserting (is (= test_record.core.MyRecord (type (map->MyRecord {}))))

dpsutton15:02:00

succeeds on first run, but not if you go to the core ns and eval that buffer

tbaldridge15:02:00

lol, why is it doing that?

dpsutton15:02:07

it's demonstrating a bug

tbaldridge15:02:09

Yeah...that's a fairly useless test

dpsutton15:02:13

it's the minimum viable example

dpsutton15:02:24

but it passes/fails depending on if its the last test or not in the deftest form

tbaldridge15:02:35

after you re-eval the parent namesapce, the types will change, and you'd have to re-eval the test namespae and re-import

dpsutton15:02:48

right, and we seemingly can't get it to behave on that step

dpsutton15:02:05

yeah, i figured the macro expansion would be pointing at older types even though they are the "same"

dpsutton15:02:41

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

tbaldridge15:02:29

If the user is re-evaluating the defrecord, and not the test namespace, then I would say that this is unsupported behavior

dpsutton15:02:49

i'm unable to get it to pass, even re-evaling the test namespace though

dpsutton15:02:55

i agree with you on the above otherwise

dpsutton15:02:01

but re-evaling the ns doesn't seem to help

tbaldridge15:02:17

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.

tbaldridge15:02:26

Well a great way to test this is to do it in a bare repl

dpsutton15:02:55

i only know how to run tests with lein test

tbaldridge15:02:56

nrepl, cider, etc. all add a lot of, stuff (for lack of a better word) that can mess up Clojure

dpsutton15:02:03

oh for sure

tbaldridge15:02:09

If you download the clojure jar.

tbaldridge15:02:18

you can do java -jar clojure.jar

tbaldridge15:02:22

And that will give you a repl,

tbaldridge15:02:31

And if you then require the test namespaces

tbaldridge15:02:44

you can switch into the namespaces and run the tests manually (they are functions)

dpsutton15:02:53

awesome. thanks

dpsutton15:02:59

i'll give that a shot

tbaldridge15:02:21

so you can either do clojure.test/run-tests to run all tests, or just call (a-test) to run it

dpsutton15:02:21

hmm, having trouble requiring the files. not exactly sure how to require them

Jeremie Pelletier15:02:47

files need to be on the classpath, then you can require them by namespace (require ‘my.namespace.tests)

cch117:02:04

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?

lockdownz17:02:46

so you can call the fn inside the fn itself

cch117:02:27

Yep, I’ve done that one before too. But why (said in a whiny voice) isn’t it also metadata on the fn object?

lockdownz17:02:22

no idea, new to clojure 😉

tbaldridge17:02:53

Why would it be metadata? Do functions ever have their name as metadata

cch117:02:38

No, but for an anonymous function, it seems useful.

cch117:02:09

This is enlightening: (meta ^:x (fn red [x] x))

cch117:02:18

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.

tbaldridge17:02:04

For what end though. It's not like these names are unique, or in some global registry.

tbaldridge17:02:40

There's also the class name that gives a semi unique name for any function

tbaldridge17:02:35

It would also impact closure creation performance, no?

swizzard19:02:26

could anyone help me with a strange leiningen issue?

swizzard19:02:46

Could not find artifact base:lein-template:jar:0.1.0-SNAPSHOT in clojars ()

swizzard19:02:49

nm, got it sorted

schmee19:02:09

anyone now how to get Spyscope working in Clojure 1.9?

schmee19:02:21

it seems that the issues is fixed in master but there is no release in maven

schmee19:02:03

hmm… I can require ‘0.1.6’ in my project.clj, but it doesn’t work when I do it in .lein/profiles.clj

schmee20:02:31

aaarrrrg, copy pasted weird quote signs around the version string, nvm!

qqq23:02:32

what's a good setup for clojurescript + atom shell ?