Fork me on GitHub
#clojure
<
2016-02-29
>
escherize05:02:05

During the previous Conj, @cfleming gave a talk about using grammars to improve error messages. At one point he mentions that there's a way to use his (install-goodness) stuff from regular clojure code, (rather than using the wonderful Cursive IDE) but I can't find a library for it

escherize07:02:54

in clojure, can I write my own tag? such as #my-fancy-datastructure-thing{7}

jimmy08:02:48

hi guys I have something like this #{:c :b :d :a} and this map [{:type :c} {:type :d} {:type :b}]. How do I sort the second map with the custom order in the first set. The result should be [{:type :c} {:type :b} {:type :d}]

doddenino08:02:44

I think sets are not ordered

schmir08:02:06

there's clojure.core/sorted-set

doddenino09:02:39

Would this be a good solution (having a vec instead of a set for the order)? (sort-by #(.indexOf order (:type %)) mymap)

jimmy09:02:02

@doddenino: good one, that will do. thanks 😄

jimmy09:02:30

I have a solution in mind to add weight to the map and sort on those, but it would be a bit clumsy

cfleming09:02:35

@escherize: I’m planning to OSS that lib but haven’t done so yet, I’ve been pretty swamped after releasing Cursive

rickmoynihan14:02:15

Has anyone seen this issue before? the date above should be parsed as 1st Apr... but the clojure REPL seems to be printing it in a different locale/timezone ↗️

rickmoynihan14:02:20

If I use the same SimpleDateFormat to print it then it works as expected - I just don't know quite what the REPL is doing

conormcd14:02:21

It's probably being parsed in your local timezone. Hence the reason the SimpleDateFormat will print it in the right timezone.

rickmoynihan14:02:57

I don't think its the parsing - I think it's clojure's printing that might be wrong

dm314:02:06

the date is printed in the default timezone

dm314:02:39

is that a problem somehow?

dm314:02:56

you can set the default timezone to UTC

rickmoynihan14:02:09

which looks correct for me

conormcd14:02:45

user=> (.parse (java.text.SimpleDateFormat. "yyyy MMM") "2012 Apr")
#inst "2012-03-31T23:00:00.000-00:00"
user=> (.parse (java.text.SimpleDateFormat. "yyyy MMM zzz") "2012 Apr GMT")
#inst "2012-04-01T00:00:00.000-00:00"

dm314:02:05

hm, sorry, the #inst seems to be without offset

dm314:02:22

so that's the SimpleDateFormat

dm314:02:50

(str (java.util.Date.)) gives a string in default zone

rickmoynihan14:02:00

ok thanks... (.parse (doto (java.text.SimpleDateFormat. "yyyy MMM") (.setTimeZone (java.util.TimeZone/getTimeZone "GMT"))) "2012 Apr")

brabster14:02:12

Hi folks, hoping for a bit of advice - I'm adding some schema validation to the system library, (eg. validate parameters when you create a new component) and I think it'd be an idea to validate by default but allow the client to turn it off.

brabster15:02:59

I'm using https://github.com/plumatic/schema and it supports controlling validation with the (with-fn-validation) form and ^:always-validate metadata but it doesn't look like there's a straightforward way to have validation on by default for a function but let the client opt to disable it... am I missing something or misthinking the problem?

dm315:02:47

@brabster - there's some 'hidden' documentation here regarding when validation is on/off: https://github.com/plumatic/schema/blob/master/src/clj/schema/macros.clj#L180

brabster15:02:23

@dm3 thanks for the tip

sandbags16:02:18

I was writing a test for a function generated by a macro and, before I remembered fn? I tried using resolve. From the REPL it worked but from the test it didn’t (where fn? worked as expected). Is there something odd about resolve… it seemed straightforward from the docs

sandbags16:02:03

(e.g. (expect (resolve ‘position-cmp)) failed where (expect (fn? position-cmp)) succeeded

noisesmith16:02:49

@sandbags: resolve does not work on locals

sandbags16:02:39

noisesmith: i’m not sure what you mean by locals

noisesmith16:02:39

not that I know this is your problem, but it's a potential issue here

noisesmith16:02:26

@sandbags: let and fn and loop create locals - bindings only visible inside their block

noisesmith16:02:39

resolve only works on vars that are interned in namespaces

sandbags16:02:56

okay i wanted to be clear since this isn’t in the context of a let or fn, but a defn

noisesmith16:02:32

well defn is just fn inside def, do you mean in the context as in inside the body using a binding created inside that body?

sandbags16:02:34

as i mentioned, using resolve from the REPL

noisesmith16:02:53

you can use let in a repl

sandbags16:02:08

i’m not sure where let has come from here

sandbags16:02:31

i’m using a macro in a namespace to defn a function

noisesmith16:02:35

(let [x 1] (resolve 'x)) - you will not find x

noisesmith16:02:49

@sandbags: never mind then, you have a separate problem

sandbags16:02:51

right, my reason for asking about locals was that i hadn’t mentioned a let

noisesmith16:02:57

sorry for the miscommunication

sandbags16:02:45

Ah, now i understand what you thought i was saying.

sandbags16:02:56

or, at least, i think I do simple_smile

noisesmith16:02:11

I was pointing out a common pitfall in resolve / eval (that they don't see locals)

noisesmith16:02:30

not assuming that was your problem yet, but mentioning just in case

sandbags16:02:45

that is useful to know in any case (and not clear from the docs)

noisesmith16:02:48

anyway, back to resolve, if called at a time when the var exists, it should see the var and return it

sandbags16:02:26

yeah, which it does at the REPL but not from the test… i mean, fn? works and is actually what i want so it’s no bother… just puzzling

sandbags16:02:59

file under “When I have infinite time for yak shaving”

noisesmith16:02:30

an alternate test would be to look up the symbol as a key in (ns-interns 'this-ns)

noisesmith16:02:41

replacing this-ns with your actual ns symbol of course

noisesmith16:02:29

clojure's ability to introspect on namespaces is actually quite extensive and pretty straightforward to use (once you understand the structure of namespaces at least)

sandbags16:02:05

This is odd, *ns* in the context of my test is user not fate.core-test

cpmcdaniel16:02:14

hmmm… anyone know how to get lein install (with :aot :all) to not include *.clj source files in the artifact?

sandbags16:02:17

that would explain why resolve is failing

sandbags16:02:36

but i’m not sure how that is happening since (ns foo) appears to set ns to foo

spacepluk16:02:05

hi there, I'm getting started with compojure but I can't find info about how to start a repl with leinigen, any idea?

jonahbenton16:02:29

@spacepluk lein repl should do it

spacepluk16:02:04

hmm, I tried that but the server is not listening even after evaluating core

spacepluk16:02:19

trying again...

spacepluk16:02:49

should I run both the server and the repl?

spacepluk16:02:53

I'm confused

jonahbenton16:02:10

you don't need to run your app to get a repl

spacepluk16:02:35

oh I see, what I want is a repl in the same environment as the running app

jonahbenton16:02:51

if you run lein repl, it's equivalent to getting dropped into your app before startup

spacepluk16:02:11

I think I understand

jonahbenton16:02:36

if you want to be able to repl into your app after it has been deployed, that takes a different approach

spacepluk16:02:01

no, I just want to test stuff while developing

Chris O’Donnell16:02:37

You can start a repl with lein repl, and if there's a main function which starts your server, you can run that from the repl.

jonahbenton16:02:48

yeah. do you know about workflows like Stuart Sierra's reloaded? http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded

spacepluk16:02:21

reading right now, thanks

jonahbenton16:02:35

sure- techniques like that using tools like Component https://github.com/stuartsierra/component or System https://github.com/danielsz/system or Mount https://github.com/tolitius/mount can help streamline the incremental development process

spacepluk16:02:00

I saw that if I run lein ring server-headless it starts the server and it reloads the files automatically but I'd still like to have a repl to inspect the state

spacepluk16:02:46

I know in general you shouldn't have state but this is a very simple "script" I'm hacking together to solve a problem temporarily

jonahbenton16:02:30

sure. so with lein ring server-headless, you can give that an :nrepl parameter which will open a port allowing you to repl into the running server

jonahbenton16:02:26

to do that, run lein ring server-headless in one terminal, and use lein repl :connect xxxx to open a repl into the server in another terminal

jonahbenton16:02:46

when you just run lein repl without the :connect option, it handles the machinery of running an instance of your application, with an nrepl port open, behind the scenes

spacepluk16:02:51

awesome, thanks simple_smile

spacepluk16:02:45

I didn't know about system it's hard to choose one hehe

jonahbenton16:02:07

heh, choices, choices. lots of them in the clojure world. simple_smile

Lambda/Sierra16:02:20

"system" is built upon "component"

spacepluk16:02:40

@stuartsierra good to know, thanks

spacepluk17:02:13

I'm still getting the hang of this, very cool stuff

edlich18:02:04

Question: Is setting a transient vector value as fast as setting an array value in java? (I need fast datastructures for chess programming) or just fast enough?

Alex Miller (Clojure team)18:02:14

on average, it is not as fast

Alex Miller (Clojure team)18:02:51

it also depends what you mean by "setting"

Alex Miller (Clojure team)18:02:08

"setting" implies to me not expanding the data structure but changing a value at an existing position (for example via assoc or assoc!), so I'm assuming that's your intent

edlich18:02:28

i mean change. But any alternative if I dont want to leave clojure emtirely (for C++ or D)?

Alex Miller (Clojure team)18:02:42

use java arrays - they work fine for stuff like this

edlich18:02:45

using java data structures direct?

Alex Miller (Clojure team)18:02:37

see aset, aget, to-array, etc

Alex Miller (Clojure team)18:02:15

depending what you want to store in them (primitives vs objects) there are more things to know as well

Alex Miller (Clojure team)18:02:47

if you're storing primitives, some extra care is needed to avoid accidentally boxing the primitives when you work on them

edlich18:02:00

cool. and greetings from a great :clojureD ! Our Videos will be available soon.

edlich18:02:49

any hint where this care is documented?

edlich18:02:42

great (and I promise to buy your book soon 🙂 )

Alex Miller (Clojure team)18:02:06

I recommend buying 10-15 at a time

Alex Miller (Clojure team)18:02:36

they are a handsome addition to any home library

hugesandwich19:02:25

Is there a simple way to rename a Java interface method when reifying, i.e. no external library needed? Example: someJavaMethod -> some-java-method I seem to remember something but can't find the old code where I did it. I might have just written something myself with a macro, but it's been awhile.

hugesandwich20:02:22

@stuartsierra: Thanks. I'll try to find whatever I did in my old code if I really need it. no big deal, just someone was asking for a fix on the names in a particular API and I didn't think it was worth the time

Lambda/Sierra20:02:59

Don't fear the Java simple_smile

hugesandwich20:02:06

no fear, I've been developing on it since the days I had a spark and an sgi machine on my desk, just a user/consumer of an api with a feature request

ghadi20:02:29

http://stable.melpa.org down for any Emacs users? (package-refresh-contents)

hans20:02:08

ghadi: works for me

ghadi20:02:51

hans: thanks for looking -- SSL or plain?

arrdem20:02:25

works fine for me...

arrdem20:02:40

plain not ssl tho

ghadi20:02:05

hmm, killing my ELPA dir seemed to do the trick.

adivish20:02:52

(remove #{1 2 3} #{1 2 4 5}) gives (4 5). I don’t understand how. is the set being used as a predicate or this is accidental?

bronsa20:02:11

it's being used as a predicate

bronsa20:02:23

you can use #{1 2 3} instead of (fn [x] (contains? #{1 2 3} x))

adivish20:02:39

this is interesting. never seen a set constructor used like this in another language. thanks simple_smile

bronsa20:02:59

@adivish: all the collections are functions in clojure

bronsa20:02:40

keywords and symbols are functions too

adivish20:02:14

I know of the theory, just that my brain isn’t wired that way.

adivish20:02:29

so for a set, it returns the element it finds. for a map, it returns the value for the key. for a vector, it indexes into the vector.

adivish20:02:37

what happens with list?

bronsa20:02:25

lists are not functions

bronsa20:02:59

I should have said most, not all simple_smile

adivish20:02:31

😄 thanks

echristopherson21:02:33

is there a good writeup somewhere about how lists are so fundamental to other Lisps but not Clojure (i.e. the reasons pro and con in the respective languages)?

jmorzins21:02:30

You might be interested in https://jafingerhut.github.io/clojure-info/clojure-for-lispers-transcript.txt "Clojure has more first class data structures"

ccann22:02:38

can anyone help me figure out how to list dependencies in my project.clj that aren’t provided when another project requires this one?

thheller22:02:02

@ccann not exactly sure what you mean but try lein with-profiles jar deps :tree

thheller22:02:54

those are all deps included on non :dev builds

ccann22:02:43

ok that helps thanks

ccann22:02:32

the gist is I have a project I want to use in two different ways — as a library, and as a standalone program. when required as a lib it doesn’t need some of the (big) deps that it needs when run as a program.

thheller22:02:13

why not make 2 projects one lib one standalone?

ccann22:02:35

I don’t have a good answer, I was hoping it could be one project

thheller22:02:49

well you'd probably juggling profiles and such alot

thheller22:02:28

checkout dependencies usually lift some of the pain when working with multiple projects

ccann22:02:26

thanks for the tip