Fork me on GitHub
#clojure
<
2018-07-16
>
lsund06:07:50

Anyone knows if the following plugin somehow works with emacs/cider? https://github.com/AvisoNovate/pretty

oscar17:07:09

That library alters the stacktrace printing functions. It doesn't integrate with your editor. It'll behave the same in a Cider REPL. The Cider Error display is already pretty good, though.

dottedmag06:07:12

@john Right, I forgot that systems are components too!

troglotit13:07:34

Did anyone used https://github.com/Factual/geo? What is the difference between region and polygon? How to compute if points is in polygon or not?

novel14:07:14

@troglotit when you talk about geographic features then you would use the notion of region. When you talk about the actual implementation, then its a polygon. You can use geo.poly/region-contains? for point in polygon computations.

troglotit14:07:53

how geofeatures differ from their implementation? hmm, but yeah, I found this https://desktop.arcgis.com/en/arcmap/10.3/tools/coverage-toolbox/overlapping-polygons-in-a-coverage-regions.htm But I’m not sure if what they meaning is common meaning.

P69615:07:30

Is there any performance trade off between the use of every? and subset? in clojure?

jumar15:07:52

subset? is implemented using every?

(defn subset? 
  "Is set1 a subset of set2?"
  [set1 set2]
  (and (<= (count set1) (count set2))
       (every? #(contains? set2 %) set1)))

jmromrell16:07:30

I'm looking for a good way to define some functionality contract - similar to a protocol, but not dependent on types. For example, I might have a contract by which my program interacts with a db with functions like query-data, transform-1, transform-2, store-data, etc. Normally I'd use a protocol for something like this, but mongo and sql connections are both maps (containing mongo and sql types as values), not distinct values Furthermore, I'd love to be able to have multiple mongo implementations (same type) and be able to def db-implementation to be one or the other. Is there a good way to approach this without having to define a bunch of my own "wrapper" types and construct one to bind to db-implementation so defprotocols can discern between them?

the2bears16:07:08

Would multimethods work @jmromrell?

jmromrell16:07:27

I could use a multimethod for each function in the contract, but it loses the benefit of a protocol where it fully encapsulates the definition and implementation of each contract in one place

👍 4
jmromrell17:07:21

When I see a protocol, it's obvious what the contract is. When I see a bunch of multimethods scattered around a large namespace, it's a lot harder to read and less clear how to extend the contract with a new complete implementation

ccann18:07:06

can anyone help me use nippy to freeze a java.io.File straight to an input stream?

hiredman18:07:11

what semantics do you expect saving a file?

hiredman18:07:55

e.g. are you serializing the file object which is basically just the path of the file without contents, or do you want to save the contents of the file?

hiredman19:07:41

the first is kind of crazy, but could be something you want for some reason, but I am going to proceed with assuming you want the second

ccann19:07:51

the second

hiredman19:07:06

almost certainly it only makes sense to get some kind of value of the contents of the file out when decoding

hiredman19:07:35

(you don't want decoding to somehow write the contents to a tmp file and then return a file object pointing to that tmp file)

hiredman19:07:17

so I would suggest the first step in encoding to be a similar process, get some kind of value of the contents of the file

ccann19:07:40

I’m trying to avoid reading the file into memory, so I was hoping I could use nippy/freeze-to-out in combination with maybe a to get an inputstream of the serialized file contents

martinklepsch19:07:09

I’m trying to extend slurp to an additional class (jGit ObjectLoader) but I’m struggling to make it work:

(extend ObjectLoader$SmallObject
  io/IOFactory
  (assoc io/default-streams-impl
         :make-input-stream (fn [x opts] (println "Opening stream") (.openStream x))
         :make-reader #'io/inputstream->reader))
I would think that this should at least print “Opening stream” when calling slurp on a SmallObject instance but instead I get an exception from input-stream->reader that SmallObject can’t be coerced to InputStream

martinklepsch19:07:39

Also let me know if this is a bad idea 😄

martinklepsch19:07:48

(extend ObjectLoader$SmallObject
  io/IOFactory
  (assoc io/default-streams-impl
         :make-input-stream (fn [x opts] (println "Opening stream") (.openStream x))
         :make-reader (fn [x opts] (io/reader (.openStream x)))))
this works

martinklepsch19:07:07

Alright, I somehow assumed make-input-stream is also used by `make-reader in some way but it seems like it’s not?

martinklepsch19:07:21

(extend ObjectLoader
  io/IOFactory
  (assoc io/default-streams-impl
         :make-input-stream (fn [x opts] (.openStream x))
         :make-reader (fn [x opts] (io/reader (.openStream x)))))
Guess this does the job.

blueberry21:07:30

As far as I remember, you cannot extend Java classes with Java interfaces. Only with protocols. (I assume io/IOFactory is an interface; if it's a protocol, then something else is a problem).

martinklepsch21:07:27

@U086AG324 it’s a protocol and the snippet above did the trick… I was confused because I - for some reason - assumed make-reader would internally use make-input-stream