Added class use example to tutorial

I was following along and noticed that it wasn't actually explained how to _use_ the object we just made. I include both the `setv` style of writing the Hy as we've been using in the rest of the docs up to this point and a more LISP-y style use of the object.
This commit is contained in:
John Patterson 2017-03-08 22:39:41 -06:00 committed by GitHub
parent 5f00921dea
commit 8fb7706a68

View File

@ -476,6 +476,11 @@ like::
Return our copy of x
"""
return self.x
And we might use it like::
bar = FooBar(1)
print bar.get_x()
In Hy:
@ -491,7 +496,20 @@ In Hy:
(defn get-x [self]
"Return our copy of 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::