Document how to supply docstrings to classes and class methods / lambdas

We want to encourage good practice, documentation-wise, amongst Hy
users!
This commit is contained in:
Christopher Allan Webber 2014-02-23 15:20:43 -06:00
parent 6829d6fb3a
commit ecfd737fb9
2 changed files with 28 additions and 4 deletions

View File

@ -814,6 +814,22 @@ function is defined and passed to another function for filtering output.
Alice Alice
Dave Dave
Just as in normal function definitions, if the first element of the
body is a string, it serves as docstring. This is useful for giving
class methods docstrings.
=> (setv times-three
... (fn [x]
... "Multiplies input by three and returns the result."
... (* x 3)))
=> (help times-three)
Help on function times_three:
times_three(x)
Multiplies input by three and returns result
(END)
let let
--- ---

View File

@ -436,11 +436,17 @@ Finally, of course we need classes! In python we might have a class
like:: like::
class FooBar(object): class FooBar(object):
def __init__(self, x): """
self.x = x Yet Another Example Class
"""
def __init__(self, x):
self.x = x
def get_x(self): def get_x(self):
return self.x """
Return our copy of x
"""
return self.x
In Hy: In Hy:
@ -448,6 +454,7 @@ In Hy:
.. code-block:: clj .. code-block:: clj
(defclass FooBar [object] (defclass FooBar [object]
"Yet Another Example Class"
[[--init-- [[--init--
(fn [self x] (fn [self x]
(setv self.x x) (setv self.x x)
@ -457,6 +464,7 @@ In Hy:
[get-x [get-x
(fn [self] (fn [self]
"Return our copy of x"
self.x)]]) self.x)]])