Created
April 3, 2015 01:31
-
-
Save egbulmer/5beb9058460b49a7006a to your computer and use it in GitHub Desktop.
Strange behaviour of function vars in the case macro
This file contains hidden or 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 foo [] (print "foo!")) | |
| (defn bar [] (print "bar!")) | |
| (defn print-foo [fb] | |
| (apply (case fb | |
| :foo #'foo | |
| :bar #'bar) [])) | |
| ; Will throw this error when defined: | |
| ; SyntaxError: Unexpected token return | |
| ; You can resolve it by removing the #' from foo and bar. | |
| ; This also works: | |
| (defn print-foo [fb] | |
| (let [foo-map {:foo #'foo :bar #'bar}] | |
| (apply (get foo-map fb) []))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment