miércoles, 15 de julio de 2015

Translate simple program from Java to Clojure

In Java:
public static double hypot (double x, double y) {
 final double x2 = x * x;
 final double y2 = y * y;
 return Math.sqrt(x2 + y2);
}
In Clojure
(defn hypot [x y]
 (let [x2 (* x x)
  y2 (* y y)]
 (Math/sqrt (+ x2 y2))
  )
)
  The execution
(println (hypot 2 3))

No hay comentarios:

Publicar un comentario