oakes / play-clj

A Clojure game library
The Unlicense
940 stars 72 forks source link

Why so many macros? #88

Closed jbeja closed 9 years ago

jbeja commented 9 years ago

First of all, awesome library!

I am a beginner to Clojure and learning for the source code I have seem so many even in case where I don't see that there isn't any benefit, am I missing something here?

oakes commented 9 years ago

Hello. My library definitely has more macros than most. The reason is that I wanted to provide a convenient syntax for using libGDX classes. For example, the following code...

(texture "clojure.png"
  :flip true false
  :set-region 0 0 100 100)

...is transformed at compile-time to this:

(let [entity (texture* "clojure.png")]
  (doto ^TextureRegion (:object entity)
    (.flip true false)
    (.setRegion 0 0 100 100))
  entity)

It makes it a lot more terse and readable. I wanted to provide this functionality for more than just the TextureRegion class, so I made a separate macro for each class that I wanted this functionality for.

jbeja commented 9 years ago

Oh I see, make sense now. Thanks for answering.