Remove some trailing spaces
This commit is contained in:
parent
538d36a7c6
commit
6bf5ebd8ee
@ -6,9 +6,9 @@ Lazy sequences
|
|||||||
|
|
||||||
The Sequences module contains few macros for declaring sequences that are
|
The Sequences module contains few macros for declaring sequences that are
|
||||||
evaluated only as much as the client code requests elements. Compared to
|
evaluated only as much as the client code requests elements. Compared to
|
||||||
generators, they allow accessing same the element multiple times. Since they
|
generators, they allow accessing same the element multiple times. Since they
|
||||||
cache calculated values, they aren't suited for infinite sequences. However,
|
cache calculated values, they aren't suited for infinite sequences. However,
|
||||||
the implementation allows for recursive definition of sequences, without
|
the implementation allows for recursive definition of sequences, without
|
||||||
resulting recursive 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:
|
||||||
@ -20,7 +20,7 @@ To use these macros, you need to require them and import other types like:
|
|||||||
|
|
||||||
The simplest sequence can be defined as ``(seq [n] n)``. This defines a
|
The simplest sequence can be defined as ``(seq [n] n)``. This defines a
|
||||||
sequence that starts as ``[0 1 2 3 ...]`` and continues forever. In order to
|
sequence that starts as ``[0 1 2 3 ...]`` and continues forever. In order to
|
||||||
define a finite sequence, ``end-sequence`` needs to be called to signal the end
|
define a finite sequence, ``end-sequence`` needs to be called to signal the end
|
||||||
of the sequence:
|
of the sequence:
|
||||||
|
|
||||||
.. code-block:: hy
|
.. code-block:: hy
|
||||||
@ -32,8 +32,8 @@ of the 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 the amount of items in the sequence and negative indexing is supported.
|
returns the amount of items in the sequence and negative indexing is supported.
|
||||||
Because both of thse require evaluating the whole sequence, calling such a
|
Because both of thse require evaluating the whole sequence, calling such a
|
||||||
function would take forever (or at least until available memory has been
|
function would take forever (or at least until available memory has been
|
||||||
exhausted).
|
exhausted).
|
||||||
|
|
||||||
Sequences can be defined recursively. The canonical example of fibonacci numbers
|
Sequences can be defined recursively. The canonical example of fibonacci numbers
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
--len-- (fn [self]
|
--len-- (fn [self]
|
||||||
"length of the sequence, dangerous for infinite sequences"
|
"length of the sequence, dangerous for infinite sequences"
|
||||||
(setv index (. self high-water))
|
(setv index (. self high-water))
|
||||||
(try (while True
|
(try (while True
|
||||||
(get self index)
|
(get self index)
|
||||||
(setv index (inc index)))
|
(setv index (inc index)))
|
||||||
(except [_ IndexError]
|
(except [_ IndexError]
|
||||||
@ -68,7 +68,7 @@
|
|||||||
|
|
||||||
(defmacro seq [param &rest seq-code]
|
(defmacro seq [param &rest seq-code]
|
||||||
`(Sequence (fn ~param (do ~@seq-code))))
|
`(Sequence (fn ~param (do ~@seq-code))))
|
||||||
|
|
||||||
(defmacro defseq [seq-name param &rest seq-code]
|
(defmacro defseq [seq-name param &rest seq-code]
|
||||||
`(def ~seq-name (seq ~param (do ~@seq-code))))
|
`(def ~seq-name (seq ~param (do ~@seq-code))))
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
0)
|
0)
|
||||||
"first element of fibonacci didn't match")
|
"first element of fibonacci didn't match")
|
||||||
(assert (= (second fibonacci)
|
(assert (= (second fibonacci)
|
||||||
1)
|
1)
|
||||||
"second element of fibonacci didn't match")
|
"second element of fibonacci didn't match")
|
||||||
(assert (= (get fibonacci 40)
|
(assert (= (get fibonacci 40)
|
||||||
102334155)
|
102334155)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user