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:
parent
6829d6fb3a
commit
ecfd737fb9
@ -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
|
||||||
---
|
---
|
||||||
|
@ -436,10 +436,16 @@ Finally, of course we need classes! In python we might have a class
|
|||||||
like::
|
like::
|
||||||
|
|
||||||
class FooBar(object):
|
class FooBar(object):
|
||||||
|
"""
|
||||||
|
Yet Another Example Class
|
||||||
|
"""
|
||||||
def __init__(self, x):
|
def __init__(self, x):
|
||||||
self.x = x
|
self.x = x
|
||||||
|
|
||||||
def get_x(self):
|
def get_x(self):
|
||||||
|
"""
|
||||||
|
Return our copy of x
|
||||||
|
"""
|
||||||
return self.x
|
return self.x
|
||||||
|
|
||||||
|
|
||||||
@ -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)]])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user