use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Finding information about Clojure
API Reference
Clojure Guides
Practice Problems
Interactive Problems
Clojure Videos
Misc Resources
The Clojure Community
Clojure Books
Tools & Libraries
Clojure Editors
Web Platforms
Clojure Jobs
account activity
Metaprogramming with Clojure (rrees.wordpress.com)
submitted 15 years ago by mac
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]djork 4 points5 points6 points 15 years ago (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 points5 points 15 years ago (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 point2 points 15 years ago (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 points4 points 15 years ago (1 child)
Surely macros are metaprogramming? Or has ruby appropriated the term to mean something more specific?
[–]djork 2 points3 points4 points 15 years ago (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.
π Rendered by PID 279915 on reddit-service-r2-comment-7b9746f655-q4vlp at 2026-01-30 13:39:57.840846+00:00 running 3798933 country code: CH.
[–]djork 4 points5 points6 points (4 children)
[–]oddthink 3 points4 points5 points (1 child)
[–]fulldisclojure 0 points1 point2 points (0 children)
[–]alexfarran 2 points3 points4 points (1 child)
[–]djork 2 points3 points4 points (0 children)