Fix grammar

This commit is contained in:
Tuukka Turto 2016-12-01 00:22:42 +02:00
parent 4219faf532
commit 538d36a7c6

View File

@ -4,24 +4,24 @@ Lazy sequences
.. versionadded:: 0.12.0 .. versionadded:: 0.12.0
Sequences module contains few macros for declaring sequences that are evaluated The Sequences module contains few macros for declaring sequences that are
only as much as the client code requests elements. Compared to generators they evaluated only as much as the client code requests elements. Compared to
allow accessing same element multiple times. Since they cache calculated generators, they allow accessing same the element multiple times. Since they
values, they aren't suited for infinite sequences. However, the implementation cache calculated values, they aren't suited for infinite sequences. However,
allows recursive definition of sequences, without resulting recursive the implementation allows for recursive definition of sequences, without
computation. resulting recursive computation.
To use these macros you need to require them and import other types like: To use these macros, you need to require them and import other types like:
.. code-block:: hy .. code-block:: hy
(require [hy.contrib.sequences [defseq seq]]) (require [hy.contrib.sequences [defseq seq]])
(import [hy.contrib.sequences [Sequence end-sequence]]) (import [hy.contrib.sequences [Sequence end-sequence]])
Simplest sequence can be defined as: ``(seq [n] n)``. This defines a sequence The simplest sequence can be defined as ``(seq [n] n)``. This defines a
that starts as: ``[0 1 2 3 ...]`` and continues forever. In order to define sequence that starts as ``[0 1 2 3 ...]`` and continues forever. In order to
a finite sequence, ``end-sequence`` needs to be called to signal end of define a finite sequence, ``end-sequence`` needs to be called to signal the end
the sequence: of the sequence:
.. code-block:: hy .. code-block:: hy
@ -30,12 +30,13 @@ the sequence:
(cond [(< n 5) n] (cond [(< n 5) n]
[true (end-sequence)])) [true (end-sequence)]))
This creates following sequence: ``[0 1 2 3 4]``. For such a sequence ``len`` This creates following sequence: ``[0 1 2 3 4]``. For such a sequence, ``len``
returns amount of items in sequence and negative indexing is suported. Because returns the amount of items in the sequence and negative indexing is supported.
both of thse require evaluating whole sequence, calling such a function would Because both of thse require evaluating the whole sequence, calling such a
take forever (or at least until available memory has been exhausted). function would take forever (or at least until available memory has been
exhausted).
Sequence can be defined recursively. Canonical example of fibonacci numbers Sequences can be defined recursively. The canonical example of fibonacci numbers
is defined as: is defined as:
.. code-block:: hy .. code-block:: hy
@ -47,7 +48,7 @@ is defined as:
[true (+ (get fibonacci (- n 1)) [true (+ (get fibonacci (- n 1))
(get fibonacci (- n 2)))])) (get fibonacci (- n 2)))]))
This results sequence of ``[0 1 1 2 3 5 8 13 21 34 ...]``. This results the sequence of ``[0 1 1 2 3 5 8 13 21 34 ...]``.
.. _seq: .. _seq: