Hacker Newsnew | past | comments | ask | show | jobs | submit | jonase's commentslogin

Disney are apparently using drones to combat paparazzi drones when filming Star Wars VIII: http://consequenceofsound.net/2016/02/drones-are-patrolling-...


I learned a lot from Mastering Bitcoin by Andreas M. Antonopoulos (http://shop.oreilly.com/product/0636920032281.do)


Sorry to jump in on an interesting discussion but I got interested in this part:

> It's also disheartening to see that the sorted-set wants things that implement Java's Comparable.

Could you quickly explain what's disheartening about Java's Comparable interface and what the available options are?


In a static language like Scala or Haskell you usually work with a type-class, which is pretty cool because you can provide implementations for types you don't control (not implying that Scala's Ordering is perfect). Instead of Java's Comparable interface I was expecting a protocol, which are almost equivalent to type-classes, or a multi-method.

Of course, in many implementations you usually also get a version of a constructor that uses a provided comparison function. However certain things, like plain numbers or strings, have a natural ordering to them, hence the need to have the sorted-set in Clojure also work with Java's Comparable. But again, I was expecting a Clojure specific protocol.

The reason for why this happens, I believe, is because protocols weren't there from the beginning, being a feature introduced in Clojure 1.2. From what I understood, in ClojureScript protocols are "at the bottom" as they say, so there's hope :-)


Thanks! So if I read your comment correctly there is nothing inherently wrong with the Comparable interface it's just that Clojure's sorted sets and maps could have used protocols instead. I can see why that would be useful for extending existing types (as you mentioned).

OTOH it’s not often I’ve seen third-party types that I wanted to be comparable but were not. In general I think that if a type does not implement a core interface you have to consider the possibility that the designer chose not to implement it for a reason.


Protocols were added in Clojure 1.2, well after the Clojure collections or stdlib were created. In a perfect world, Clojure itself could leverage protocols more widely across the stdlib. For practical reasons, this is difficult now.


Maybe a mitigating factor is that any Clojure 2-arg function extends AFunction which implements Comparator. So any Clojure function that returns -1/0/1 will work transparently. Example, use - as a comparator:

=> (sorted-set-by - 2 9 3 5 4) #{2 3 4 5 9}


At akvo.org we are using Clojure in production and hopefully soon also Clojurescript.

We are using Clojure on top of existing Java functionality, and we're moving our Ember based Dashboard over to Clojurescript/Om.


I'm very interested in working with SVG in the browser and have found it to work pretty well with React. I built a demo (Code: https://github.com/jonase/elements, App: http://jonase.github.io/elements/) using one of the (increasing number of) React wrappers for ClojureScript (Chrome only for the moment I'm afraid)


Maybe mori could include core.rrb-vector[1]. Other interesting persistent data structures (by the same author) are persistent sorted maps and sets[2].

[1] https://github.com/clojure/core.rrb-vector [2] https://github.com/clojure/data.avl


Weekend project? That's amazing! Is the source available? I would love to read it.


https://github.com/jackschaedler/goya

I'm just learning Clojure and Om, so the code is probably very nasty.


Am I missing something here or is the algorithm you describe simply: "Find the smallest even and odd number in a set of numbers?" This shouldn't be hard to do in any language.


That's exactly what it is and I agree. Clojure is awesome because you can almost write the actual code just the pseudo code.

> But, when one of these functions takes or returns something you don't expect, debugging the problem usually took me 30 minutes. The error messages were very opaque to me.


>you can almost write the actual code just the pseudo code.

Yes, often true. E.g. in this case:

  (->> [2 3 4 7 5 3 11 12 7] ;collection
     (group-by even?)        ;get a map of evens and odds
     vals                    ;get just the values
     (map sort)              ;sort them
     (map first))            ;first is smallest
(disclaimer: there's probably prettier ways to write this - I was just trying to keep it simple)

I agree that there are sometimes inscrutable errors. For me it's often because of a type conflict between a function and what it's operating on.

Example: I'm a little rusty and when I tried to quickly code the example above I did this:

  (->> [2 7 5 3] (partition-by even?) vals)
And got:

  ClassCastException clojure.lang.Cons cannot be cast to java.util.Map$Entry  clojure.lang.APersistentMap$KeySeq.first (APersistentMap.java:152)
Doh! I wanted "group-by". And partition-by doesn't make a map! But why this specific error? Frankly I'm not sure. I'd probably have to look at the source. My sin of course was trying to compose operations in one go, rather than build them up by baby steps in the REPL. I don't think the errors ever get that much more readable, but you start to recognize the category of error you've made by the type of error that's thrown.

Spending time on 4Clojure is very helpful to build your intuition for this.


You can make that somewhat more close to the correct computation, you don't need to sort the lists, you just need min values.

  (->> [2 3 4 7 5 3 11 12 7]
       (group-by even?)
       vals
       (map #(apply min %)))</pre>
However, operation like this can be made much more readable if you actually use variables like this:

  (defn min-even-odd [xs] 
    (let [evens (filter even? xs)
          odds (filter odd? xs)] 
       (list (apply min evens) (apply min odds))))

  (min-even-odd [2 3 4 7 5 3 11 12 7])
Which is a bit longer, but I think it makes more sense.


The best source I've found is at http://rewriting.loria.fr which contains lots of interesting papers.


If someone is interested in how kibit is implemented I've got some slides at http://jonase.github.io/kibit-demo/. It's quite easy and a good (I think) introduction to core.logic.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: