Fork me on GitHub
#clojure
<
2016-05-04
>
fasiha00:05:53

Is my understanding right? transduce is basically reduce, except instead of (reduce fn (xform coll)) you call it as (transduce xform fn coll), provided xform is a composition of map, filter, take, drop, replace, etc. As a bonus, then, such an xform can be used with into and channels and etc. Is this perspective incorrect?

ghadi00:05:03

sounds about right. the definition of transduce is almost literally (reduce (xform f) init coll) -- note the xform wraps the function

ghadi00:05:20

coltnz: DSL-like arguments are generally frowned upon in clojure. It is more idiomatic to use generic collection fns to transform sequences, wrt filtering. (file-seq f :dir) is implemented:

(let [dir? (memfn ^File isDirectory)]
  (filter dir? (file-seq f)))

coltnz01:05:57

thanks for the reply @ghadi on reflection you are right about the 'dsl' aspect, i don't get your point on implementation, isnt the point that we all have to do it cos we seldom want the collection as is (if it didnt have '.' it would be more useful)

coltnz01:05:29

perhaps i should be less ambitious and suggest

coltnz01:05:04

(defn file-seq [dir children-only?] 

coltnz01:05:30

though going to

coltnz01:05:46

(defn file-seq [dir children-only? files-only?] 
would be good too

coltnz01:05:37

i note File/listFiles doesnt include "."

ghadi01:05:52

That's also a small DSL, but the issues go beyond syntax. While it looks like a convenience, it raises more questions than it answers: what are all the possible filter options? what order are they listed in? what if there are conflicting combinations of options? The implementor of file-seq need not be in the business of providing conveniences... Just let the user do what they want with the abstraction (the seq).

coltnz01:05:43

If we gonna reduce that to a dsl, then theres precedent... I posit that file-seq is almost always used with a filter (often after being erroneously used without one) and that doc string to explain the option(s) needn't be burdensome even in the prevailing terse style but <shrug>

clumsyjedi05:05:41

question about transducers:

(let [xform (comp (map :data) (filter even?))
        ch (chan 1 xform)]
    (clojure.core.async/>!! ch {:data (range 10)})
    (clojure.core.async/<!! ch))
The above returns nil because the (filter even?) receives a single arg, which is a collection, rather than the elements of the coll itself, ie the numbers 1-10

clumsyjedi05:05:03

How do I split these items out so they can be processed individually

clumsyjedi05:05:25

google keeps pointing me at an fn called eduction but I con’t figure out how to use it

stask05:05:35

@clumsyjedi: something like this: ` (let [xform (comp (mapcat :data) (filter even?)) ch (clojure.core.async/chan 1 xform)] (clojure.core.async/>!! ch {:data (range 10)}) (clojure.core.async/close! ch) (clojure.core.async/<!! (clojure.core.async/into [] ch))) `

stask05:05:59

@clumsyjedi: mapcat instead of the map

mariogintili11:05:36

hello peeps, not really relevant to this channel but I dont know where to post this message

mariogintili11:05:45

where could I get a list of companies using clojure in London?

danielcompton11:05:05

@mariogintili: there is a London Clojurians email list, and a London Clojurians Job list

danielcompton11:05:37

You could also talk to @jonpither at Juxt, he’s pretty friendly and might be able to help

jm11:05:35

Anyone have tips around handling user facing data validation errors in compojure-api/schema? I’ve looked at bouncer but using that would mean a lot of duplication between that and schema.

jtackett11:05:13

Does clojure join preserve the order of the list?

mpenet11:05:05

jtackett: clojure.string/join yes

thiagofm12:05:34

Hello everyone. I need some feedback regarding Exceptions, I've read somewhere that Exceptions in clojure aren't frequently used. I'm writing a lib and want to know how do you think it would fit better:

thiagofm12:05:13

The lib processes images using the command line. I'm doing a validation over the allowed options, to help whoever uses it. My current implementation whenever that option doesn't exist, I raise a java (Exception.), what would be a good contrasting approach to that? Or should I create my own specific Exception? What do you recommend/would like a library like this one to behave?

hans12:05:10

@thiagofm: we like slingshot.

borkdude12:05:43

@thiagofm: do you mean when someone passes an invalid option from the command line? an exception is a bit weird then imho

hans12:05:59

@thiagofm: there is a whole school of people who think that exceptions suck, but the alternatives ain't better in my opinion and i'd rather see a program fall on the face than paper over an error because some error code is not checked.

hans12:05:34

@borkdude: we like to have one exception handler in our -main function and translate exceptions into user-consumable message exactly there.

borkdude12:05:48

do you use https://github.com/clojure/tools.cli ? seems like a handy lib

hans12:05:19

@borkdude: yes. we don't love it but we use it simple_smile

borkdude12:05:35

@hans: that's a way to do it, but afaik an exception is not needed if you have something like {:errors [...]}, but yeah, it's possible of course

borkdude12:05:47

the benefit of working with {:errors [....]} is that you can display multiple errors (unless you use the exception to wrap a collection)

danielcompton12:05:30

@thiagofm: take a look at ex-info, instead of raw Java exceptions. They’re more idiomatic, and let you bundle arbitrary data in an exception and easily get it out again with ex-data

thiagofm12:05:14

@hans: slingshot is what I had in mind

thiagofm12:05:53

@danielcompton: the shell library I use, uses this approach. Will take a look

thiagofm12:05:54

@borkdude: I mean that somebody has written a program passing a wrong argument. For this case I would like the programmer to see that this command doesn't exist or that a typo has been made

ikitommi14:05:37

@jm: plumatic schema & human readable errors seems to be unsolved. I would suggest writing / commenting issue to Schema itself.

korny14:05:54

Hi folks - anyone know of a way to get pretty exception stack traces, like those in https://github.com/mmcgrana/clj-stacktrace in a log output by log4j?

korny14:05:29

I’ve got a feeling this might be fiddly, as the stack traces are formatted by some internal log4j appender, not by clojure code. But I’m hoping someone can prove me wrong...

korny14:05:10

(I’m actually using tools.logging but have log4j as the underlying logger)

darwin15:05:34

@korny: not sure about enhancing stack traces, but I ended up implementing my own log4j “layouter" when printing logs to console, I prefer to have logger name and then actual content indented at specific column (multi-line text aware) here is the implementation: https://github.com/binaryage/dirac/blob/master/src/logging/dirac/logging/utils.clj#L59 you could implement a formatter to process LoggingEvent in a different way, maybe using parse-exception from clj-stacktrace

korny15:05:22

neat stuff - thanks

mping15:05:18

Hi, anyone familiar with pulsar actors?

borkdude15:05:54

@mping: I only did the tutorial, they look awesome

mping15:05:17

but my impl is borked 😄

jm22:05:34

@ikitommi: thanks for the reply

bostonaholic23:05:37

is there a place to update my information given on the Clojure Contributing Agreement?

dimiter23:05:10

Hey, if I have a Java Object with a number of public attributes, what is the easiest way to turn that into a Map.

dimiter23:05:45

Say I have the following properties on the object.

name: someName
state: OK
agentVersion: 60.0.59410.0
stage: UNKNOWN
opswLifecycle: MANAGED
defaultGw: 10.11.22.1
hypervisor: false
firstDetectDate: null
lastScanDate: null

dimiter23:05:09

I want to turn that list of props into a map

danielcompton23:05:17

@dimiter do you want all of the properties to be in the map, or a subset of them?

dimiter23:05:25

All of them, I can dissoc any ones I dont need later.

hiredman23:05:33

have you tried bean?

hiredman23:05:46

or seen wallhack?

hiredman23:05:05

wallhack gives you an object that implements ILookup, which is not entirely a map, but you can call get and use destructuring on it

didibus23:05:32

Question about macros. Do they expand at static compile time, as in, do they expand when I'm creating my jar, or are they going to expand at run-time compile time, that is, when Clojure loads the classes and dynamically compiles them?