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
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
---

View File

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