Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Object Oriented Macros (Clojure) (dosync.posterous.com)
35 points by swannodette on Aug 23, 2011 | hide | past | favorite | 6 comments


Could use some comments there.


Anything in particular that you're interested in?


- I don't read Clojure very well, so the syntax is my best guess, and will be for any other people who aren't Clojurists. In particular, what do COMMENT and DERIVE do? And, is MATCH a Clojure primitive?

- What exactly are you doing that's object oriented? You've changed the type, which causes a cascade of changes relating to analysis.

I'm sorry, but I must have the stupid this morning, because I don't think I am getting what you are doing. :(


This is the pattern matching library described here: http://news.ycombinator.com/item?id=2864482

match is not a Clojure primitive. match is macro that is an optimizing pattern match compiler. It works on all of Clojure's data structures.

The problem is that for things which are not Clojure data structures - primitive arays and bytes - how do you pattern match those without introducing overhead? Enumerating all the possibilities is out of reach. Adding an abstraction means introducing some kind of wrapper type - ridiculous performance loss when you dealing with primitive arays and byte.

So you can derive the compilation procedure (::match.core/vector, here shortened to ::m/vector) and specify what code to put in the critical locations. Instead of subclassing objects, we're "subclassing" the compiler algorithm and saying put in this code if the match expression has annotations like ::int.

The result is that we can match arrays 30 times faster than Scala, 10 times faster than Racket. And we have bit level pattern matching a la Erlang in what ... 10 lines of code?


why is it (a | b) and not (:or a b)?


It may change, depending on feedback. I happened to be shooting for the feature set present in OCaml and Haskell so the influence shows.




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

Search: