domingo, 6 de octubre de 2013

Buscar documentación en Clojure

Similar que la función help de python, en clojure existe doc, con esta función podemos ver documentación de otra función, como por ejemplo:

=> (doc str)
-------------------------
clojure.core/str
([] [x] [x & ys])
  With no args, returns the empty string. With one arg x, returns
  x.toString().  (str nil) returns the empty string. With more than
  one arg, returns the concatenation of the str values of the args.
nil

Por supuesto que doc muestra lo que esta documentado de la función, no hace magia, si no documentamos nuestras funciones doc no puede mostrar nada.

Otras veces no sabemos que función utilizar y para esos casos esta find-doc que pasandole una expresión regular busca las funciones que se le parecen:

=> (find-doc "reduce")
-------------------------
clojure.core/areduce
([a idx ret init expr])
Macro
  Reduces an expression across an array a, using an index named idx,
  and return value named ret, initialized to init, setting ret to the
  evaluation of expr at each step, returning ret.
-------------------------
clojure.core/reduce
([f coll] [f val coll])
  f should be a function of 2 arguments. If val is not supplied,
  returns the result of applying f to the first 2 items in coll, then
  applying f to that result and the 3rd item, etc. If coll contains no
  items, f must accept no arguments as well, and reduce returns the
  result of calling f with no arguments.  If coll has only 1 item, it
  is returned and f is not called.  If val is supplied, returns the
  result of applying f to val and the first item in coll, then
  applying f to that result and the 2nd item, etc. If coll contains no
  items, returns val and f is not called.
-------------------------
...
nil



No hay comentarios.:

Publicar un comentario