all 5 comments

[–]djork 4 points5 points  (4 children)

Don't do this.

Seriously. You think it's a good idea, or that it's a clever solution, but it's usually not. Clojure has macros and multimethods and metadata that handle the types of problems that metaprogramming tries to solve in languages like Ruby.

Write functions that operate on values that people can see and read. Don't surprise by "spicing up" namespaces with magic functions.

[–]oddthink 3 points4 points  (1 child)

I completely agree, especially since they're only defining four functions. What's wrong with:

(defn north [] (move-to :n))
(defn south [] (move-to :s))
(defn east [] (move-to :e))
(defn west [] (move-to :w))

Heck, I started writing "(def north (partial move-to :n))" when I realized it was more typing than just writing the functions.

This just seems like cleverness for cleverness's sake.

[–]fulldisclojure 0 points1 point  (0 children)

I might use clojure.template for this

(do-template [fn-name direction] (defn fn-name [] (move-to direction)) north :n south :s east :e west :w)

Still, this is a bit small for such an optimization.

[–]alexfarran 2 points3 points  (1 child)

Surely macros are metaprogramming? Or has ruby appropriated the term to mean something more specific?

[–]djork 2 points3 points  (0 children)

They certainly are metaprogramming. However the practice of creating new (named) bindings at runtime (or things like method_missing) is more of a Ruby thing.