From 5d7b069ecb4c9540ec8e29f9230867f41bb9a18d Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Sat, 9 Mar 2019 07:43:41 +0000 Subject: [PATCH] Add collections indexes and slices tutorial This change adds to the tutorial the hy way of accessing array. --- docs/tutorial.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 70522e6..af5523f 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -5,7 +5,6 @@ Tutorial .. TODO .. .. - How do I index into arrays or dictionaries? -.. - How do I do array ranges? e.g. x[5:] or y[2:10] .. - Blow your mind with macros! .. - Where's my banana??? @@ -342,6 +341,19 @@ The equivalent in Hy would be: (for [i (range 10)] (print (+ "'i' is now at " (str i)))) +Python's collections indexes and slices are implemented +by the ``get`` and ``cut`` built-in: + +.. code-block:: clj + + (setv array [0 1 2]) + (get array 1) + (cut array -3 -1) + +which is equivalent to:: + + array[1] + array[-3:-1] You can also import and make use of various Python libraries. For example: