1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 08:20:27 +00:00

Improve lazy2iter and fix a typo in specials.c

This commit is contained in:
Gavlooth 2018-03-23 15:18:04 +02:00
parent 41d5b5cb90
commit 0ebc95aa2b
2 changed files with 18 additions and 20 deletions

View File

@ -109,15 +109,14 @@ body once, and then memoizes the result."
#Iterators is a conscept that looks a lot like lazy seq #Iterators is a conscept that looks a lot like lazy seq
#The following functions turn iterators to lazy seq and vice versa #The following functions turn iterators to lazy seq and vice versa
(defn- iter-self
[next]
(delay (tuple (next) (iter-self next))))
(defn iter2lazy (defn iter2lazy
"Create a lazy sequence froma an iterator" "Create a lazy sequence from an iterator"
[iter] [iter]
(def {:more more :next next} iter) (def {:more more :next next} iter)
(iter-self next)) (if (more)
(delay (tuple (next) (iter2lazy iter)))
empty-seq))
(defn lazy2iter (defn lazy2iter
"turn a lazy-seq to an iterator" "turn a lazy-seq to an iterator"
@ -138,8 +137,7 @@ body once, and then memoizes the result."
#data structures as their values are references to this #data structures as their values are references to this
#data structures. Same is true for iterators #data structures. Same is true for iterators
(defn filter2 [pred coll] (defn filter2 [pred coll] (iter2lazy (filter pred coll)))
(tail (iter2lazy (filter pred coll))))
(def arr [0 -1 -2 33 -3 0 302 -3 2 8 54 3 -2 0]) (def arr [0 -1 -2 33 -3 0 302 -3 2 8 54 3 -2 0])

View File

@ -614,7 +614,7 @@ DstSlot dstc_fn(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
return ret; return ret;
} }
/* Keep in lexographic order */ /* Keep in lexicographic order */
static const DstSpecial dstc_specials[] = { static const DstSpecial dstc_specials[] = {
{":=", dstc_varset}, {":=", dstc_varset},
{"ast-quote", dstc_astquote}, {"ast-quote", dstc_astquote},