Fork me on GitHub
#clojure
<
2015-07-15
>
rickmoynihan08:07:07

Just wondering if there are any clojure wrappers over java 8 streams & lambda's etc...

andrea.crotti08:07:28

is there really no way to add a dependency without restarting the REPL?

andrea.crotti08:07:01

sometimes I want to try out something with an existing library in a project that doesn't have that dependency to see how it works

andrea.crotti08:07:05

before adding that dependency..

andrea.crotti08:07:30

alternatively maybe I should just keep a project where I have all the possible libraries in the world available and use that for trying out stuff instead

pupeno08:07:13

When my library depends on Clojure 1.6.0, does it mean it’ll also works with 1.7.0?

andrea.crotti08:07:42

@pupeno: I think it's not guaranteed

pupeno08:07:36

Oh, what I meant is, when doing dependency resolution, is lein assuming that it will work? so if someone is using clojure 1.7.0 will it just try to use my library or get an error, because my library claims 1.6.0?

pesterhazy08:07:54

you can do (./pull 'org.clojure/data.xml "0.0.8") in a running repl

pesterhazy08:07:02

with vinyasa, that is

andrea.crotti08:07:41

@pupeno: no that should be fine

andrea.crotti08:07:50

but still you need to test if everything still works as before

pupeno08:07:21

Version specification with lein makes me a bit nerveous as it doesn’t have >= or ~= like gem/bundle in Ruby.

andrea.crotti08:07:04

awesome article thanks

pupeno09:07:14

I should use the version 0.1.0-SNAPSHOT should be while developing, then, for release, I should switch that to 0.1.0 and then, when starting developing 0.2.0-SNAPSHOT?

ordnungswidrig10:07:57

@pupeno: the x-SNAPSHOT versions come before the x version.

ordnungswidrig10:07:26

@pupeno: and the get attached a timestamp and are refreshed daily by default if used as an attachment

andrewmcveigh10:07:10

@pupeno: And if you haven’t already seen it… http://semver.org/

pupeno10:07:33

@ordnungswidrig: yes, I’m currently developing 0.1.0-SNAPSHOT so, I should change that to 0.1.0 to release, and then change it to 0.2.0-SNAPSHOT to keep on developing. x-SNAPSHOT comes before x… or am I wrong here?

ordnungswidrig10:07:00

no, that’s correct. lein release will do that revision dance for you, btw.

pupeno10:07:41

@andrewmcveigh: I’m familiar with semantic versioning. I actually wrote a blog post about it back when it was new. But this SNAPSHOT is not part of it, which is the confusing part.

pupeno10:07:59

ordnungswidrig: ah… cool simple_smile

andrewmcveigh10:07:17

@pupeno: Cool, I thought you would have…

pupeno10:07:00

How important is it to gpg-sign the release? Is this checked?

andrewmcveigh10:07:18

lein-release will try to sign the git-tag, and the jar. If you’re wanting to release to http://clojars.org, you cannot ‘promote’ an unsigned release. How important that is, I guess it’s up to you.

andrewmcveigh10:07:14

It proves that the release is from you, so that could be important to consumers of the lib.

martinklepsch11:07:22

@pesterhazy: @andrea.crotti fwiw with boot this is trivial (boot.core/set-env! :dependencies #(conj % ‘[your.lib “0.1.0”])) simple_smile

martinklepsch11:07:30

also launching a repl with boot -d your.lib repl has similar effects

wilkerlucio13:07:11

I have a namespace in which I would like to delegate some functions to another namespace, I'm doing that by simply defing a reference, like: (def a other-ns/a), there is any other way to do about this?

wilkerlucio13:07:35

I wonder if there is some special declaration at the (ns) to accomplish the same

ragge13:07:48

@wilkerlucio: there isn't, but ther are things like potemkins import-vars to accomplish this: https://github.com/ztellman/potemkin#import-vars

wilkerlucio13:07:53

thanks @ragee, my only issue with the (def) solution is that Cursive doesn't follows this kind of definition nicely (when auto-completing, it displays as a simple var, instead of function with the expected arguments)

ragge13:07:17

@wilkerlucio: i think potemkins implementation brings in var metadata (like arglist)

wilkerlucio13:07:00

@ragee cool, I'll try that

ragge13:07:29

@wilkerlucio: although, I'm not sure that will work with cursive anyway as it does static analysis, but @cfleming can correct me here

wilkerlucio13:07:03

@ragee: I'm actually just writing an email to the cursive list asking if Cursive could follow those kind of alias automatically

wilkerlucio13:07:40

@ragge, sorry, I was typing your user name wrong all this time...

wilkerlucio13:07:03

@ragge: just letting you know, I tried ot manually set the metadata for the argslist and it didn't worked... so I think it wouldn't really matter me to use potemkin for that, hopefully Cursive can do the following in future

stuartsierra15:07:07

This is where I recommend creating fewer, larger name spaces instead of playing tricks with Vars. @ragge @wilkerlucio

ragge15:07:33

oh, I totally agree with that

stuartsierra15:07:07

Playing with Vars is likely to confuse static analysis tools, and can have unexpected consequences with things like alter-var-root.

roberto15:07:10

I’m guilty of having small namespaces. Trying to break that habit from the OO world. Going thru withdrawal syndrome.

wilkerlucio15:07:59

@stuartsierra: so, in my case the aliases that I'm making are for a foreign namespace (datomic in this case), on my own namespaces I try to keep a small number, but on this case I wanted a namespace that has some datomic api functions + some utilities of mine (because what was happening is that all the times I was requiring both namespaces, datomic and my utils, with the aliases I can include only mine), any further suggestion here?

stuartsierra16:07:09

@wilkerlucio: That's confusing to someone who has to read your code, because they can't tell which functions are yours and which are part of the Datomic API.

stuartsierra16:07:10

I believe the risk of confusion greatly outweighs the "convenience" of a single namespace.

roberto16:07:43

:thumbsup: ^

roberto16:07:28

even in OO code, I hate it when I have to go deeper and deeper down the inheritance chain to find the code that is actually doing something.

roberto16:07:16

importing vars (or creating aliases like this), I think, would lead to a similarly sour experience.

stuartsierra16:07:22

My biases may be different from yours. As a consultant, I spend a lot of time reading other peoples code, so I place a high value on being able to understand how a piece of code works just by reading it.

colin.yates16:07:12

@stuartsierra: +1 - I wish developers understood the difference between encapsulation and abstraction - just moving stuff around really isn’t abstraction.

colin.yates16:07:00

@stuartsierra: What I meant to say was that I don’t think that bias is that different, we all end up reading code, either our own 6 months later or our team mates. We should all have that bias

colin.yates16:07:48

when implementing a protocol in another namespace do I have to (:import) it or is it sufficient to (:require the-ns :as the-ns) and then (defrecord Myrecord [] the-ns/TheProtocol (…)))?

colin.yates16:07:16

so in ns-1 I have (defprotocol AProtocol (say-hi [this])) what do I have to do in ns-2?

colin.yates16:07:41

(I am running into intermittent errors with ‘No implementation of method X on protocol’ when reloading code)

cfleming16:07:17

@wilkerlucio: @ragee: Cursive does actually support Potemkin’s implementation.

cfleming16:07:40

I’ll see if I can add support for the (def x y) solution too

wilkerlucio16:07:53

in my project I like having to include a single namespace because it's happening often, and in my case I'm the only developer and this convenience is being very nice, maybe worth splitting later but I'll keep it there for now, but I understand your point on the understanding

wilkerlucio16:07:03

@cfleming: nice, I would love to have that working

jthomson16:07:02

@colin.yates: require is sufficient. the reloading issues could very well be that the protocol is being re-def'd but the record isn't. this is a known limitation of protocols (will try to find the google groups thread). one 'hacky' solution is to wrap protocols in a defonce. Another is to keep all your protocols in a namespace that doesn't get reloaded.

colin.yates16:07:25

that’s right - I remember that now. Thanks @jthomson for the prompt.

stuartsierra17:07:27

@colin.yates: Protocols are Vars. Records/types are not.

colin.yates17:07:20

I see, so I can safely do other-ns/Protocol but I have to (import) defrecords

mateusz-fiolka17:07:28

Anyone knows why pprint doesn't return it's argument? It would make it so much convenient.

stuartsierra17:07:39

@colin.yates: Exactly. Or use the record constructor functions like ->Foo map->Foo, which are normal Vars.

stuartsierra17:07:28

@mateusz-fiolka: Probably because the typical use is at the REPL, where you don't want to see the non-pprinted value immediately after the pprinted one.

stuartsierra17:07:49

Most of the side-effecting functions return nil, like println.

gtrak18:07:14

mateusz-fiolka: I have a version of the dbg macro that uses pprint

gtrak18:07:23

it returns a value

voxdolo21:07:07

I have a situation where I have a seq of some zippers (sourced from XML) and in the event that the XML is erroneous, I want to catch the exception… I have a test in place to make this assertion about the behavior when supplied with faulty XML.

voxdolo21:07:50

However, since the datastructure is lazy, I can't simply (is (search/xml->maps xml)) since the error isn't encountered until the test tries to realize the data structure

voxdolo21:07:31

and the (try <code producing zippers here> (catch Exception e <etc>)) code won't catch it at this point

voxdolo21:07:26

I can get the test to pass if I force the data structure to be realized inside the search/xml->maps function, but that's obviously suboptimal

voxdolo21:07:37

any thoughts?

devn21:07:55

you could maybe set the default uncaught exception handler for your tests?

devn21:07:30

(so if it sees an instance of XMLParseException or whatever, it drops it in the cache)

devn21:07:07

but i suspect you want to check (thrown? ...) or something, right?

voxdolo21:07:21

I want to check that it's not thrown...

devn21:07:40

what XML parsing lib are you using?

voxdolo21:07:44

as in the above (is (search/xml->maps xml))

voxdolo21:07:55

clojure.data.xml and clojure.data.zip

voxdolo21:07:22

the XML is all manipulated/parsed in zippers, which is where the laziness comes in

voxdolo21:07:59

the functions operating on the zippers do things like type casting

voxdolo21:07:31

and where the XML is in an unexpected format, those type casts could end up doing things like (Integer/parseInt nil)

voxdolo21:07:04

so I'm trying to catch that exception, log it and continue with the rest of the parsing (since one sibling in the xml hierarchy shouldn't stop all the parsing)

voxdolo21:07:18

I think this is a test only issue though

voxdolo21:07:34

in the application, if I get a bad response, it handles it as expected

voxdolo21:07:21

under test, the structures stay lazy until something prompts them to be evaluated, at which point the exception occurs outside of where I'm catching the local exception at

devn21:07:38

and you force them in practice?

devn21:07:46

why not just force it in test?

devn21:07:53

oh, i see, nevermind

voxdolo21:07:27

yeah, I don't have to force it in the actual app code… I think it's a side-effect of how the is macro works, but I'm not entirely sure

voxdolo21:07:03

in practice, I don't know that it would be a terrible thing to force realization… but I hate to change app code to make a test work when I can see it behaving properly

devn21:07:05

again though, if you set the default uncaught exception handler, the exception will occur outside of where you're catching the local exception, but you could do something with it to make it visible to you

devn21:07:12

like drop it in an atom or something

voxdolo21:07:40

the point of the test is to assert that the exception is handled gracefully

devn21:07:58

heh, round and round we go!

devn21:07:09

what is the actual exception?

voxdolo21:07:31

I have n sibling xml nodes where one of them has unexpected structure. I want to see that n-1 of them are as expected and n is just an empty version of the same representation

voxdolo21:07:39

it's a null pointer exception simple_smile

voxdolo21:07:54

because the zipper points at a node that doesn't exist in the malformed XML

voxdolo21:07:22

and it's doing an Integer/parseInt to type cast the text of the node

voxdolo21:07:18

I'll see if I can put together a minimal example

devn21:07:33

that'd be helpful

devn21:07:43

of course, someone may just know the answer

devn21:07:51

but i'll take a peek

voxdolo22:07:46

unable to reproduce in a simpler setting… ¯\(ツ)

voxdolo22:07:18

either it's too much simpler or I'm missing something… either way, I'll have to go look at it again.

voxdolo22:07:36

thanks anyway for the offer devn