Skip to content

Instantly share code, notes, and snippets.

@mattyw
Created January 8, 2012 06:01
Show Gist options
  • Save mattyw/1577418 to your computer and use it in GitHub Desktop.
Save mattyw/1577418 to your computer and use it in GitHub Desktop.
Pythagoras' theorem using J's under idiom in Clojure. See (http://mattyjwilliams.blogspot.com/2012/01/under-new-idiom-from-j-language.html)
(defn under [verb, obverse, func x y]
(obverse (func (verb x) (verb y))))
(defn sqrt [x]
(Math/sqrt x))
(defn square [x]
(Math/pow x 2))
(defn pythagoras [x y]
(under square sqrt + x y))
(println (pythagoras 3 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment