Merge pull request #1249 from john-patterson/patch-1
Added class use example to tutorial
This commit is contained in:
commit
13170f8ee7
2
AUTHORS
2
AUTHORS
@ -75,3 +75,5 @@
|
|||||||
* Sergey Sobko <s.sobko@profitware.ru>
|
* Sergey Sobko <s.sobko@profitware.ru>
|
||||||
* Philip Xu <pyx@xrefactor.com>
|
* Philip Xu <pyx@xrefactor.com>
|
||||||
* Charles de Lacombe <ealhad@mail.com>
|
* Charles de Lacombe <ealhad@mail.com>
|
||||||
|
* John Patterson <john@johnppatterson.com>
|
||||||
|
|
||||||
|
@ -476,6 +476,11 @@ like::
|
|||||||
Return our copy of x
|
Return our copy of x
|
||||||
"""
|
"""
|
||||||
return self.x
|
return self.x
|
||||||
|
|
||||||
|
And we might use it like::
|
||||||
|
|
||||||
|
bar = FooBar(1)
|
||||||
|
print bar.get_x()
|
||||||
|
|
||||||
|
|
||||||
In Hy:
|
In Hy:
|
||||||
@ -491,7 +496,20 @@ In Hy:
|
|||||||
(defn get-x [self]
|
(defn get-x [self]
|
||||||
"Return our copy of x"
|
"Return our copy of x"
|
||||||
self.x))
|
self.x))
|
||||||
|
|
||||||
|
And we can use it like:
|
||||||
|
|
||||||
|
.. code-block:: clj
|
||||||
|
|
||||||
|
(setv bar (FooBar 1))
|
||||||
|
(print (bar.get-x))
|
||||||
|
|
||||||
|
Or using the leading dot syntax!
|
||||||
|
|
||||||
|
.. code-block:: clj
|
||||||
|
|
||||||
|
(print (.get-x (FooBar 1)))
|
||||||
|
|
||||||
|
|
||||||
You can also do class-level attributes. In Python::
|
You can also do class-level attributes. In Python::
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user