Created
January 21, 2012 01:47
-
-
Save wjlroe/1650711 to your computer and use it in GitHub Desktop.
metadata how does it work?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn | |
^{:user/help-msg "Exit back to your shell"} | |
exit | |
"exit the program" | |
[] | |
(System/exit 0)) | |
et4te
commented
Jan 21, 2012
Doing (meta exit) or even (meta user/exit) won't work here because we're looking for metadata on a var (functions are the equivalent of (def f (fn [] ...))).
user>
exit
user/exit
user> #'exit (var user/exit)
Yeah, this was pointed out to me on #clojure. Seems obvious to me now :)
Problem is, now I can't work out how to have 2 vars that reference each other - seems the clojure compiler can only let you reference vars that were defined above you in the code.
I'e tried messing with (resolve (symbol "help"))
to get around that but had no luck :(
Oh I've solved that now.
To have two vars that refer to each other, you need to define one first:
(def something)
(defn another []
(let [blah (something)]
blah))
(defn something []
(format "hi: %s" (meta #'another)))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment