mirror of
https://github.com/janet-lang/janet
synced 2025-01-23 13:46:52 +00:00
commit
3c57980ef1
@ -109,15 +109,14 @@ body once, and then memoizes the result."
|
||||
#Iterators is a conscept that looks a lot like lazy seq
|
||||
#The following functions turn iterators to lazy seq and vice versa
|
||||
|
||||
(defn- iter-self
|
||||
[next]
|
||||
(delay (tuple (next) (iter-self next))))
|
||||
|
||||
(defn iter2lazy
|
||||
"Create a lazy sequence froma an iterator"
|
||||
"Create a lazy sequence from an iterator"
|
||||
[iter]
|
||||
(def {:more more :next next} iter)
|
||||
(iter-self next))
|
||||
(if (more)
|
||||
(delay (tuple (next) (iter2lazy iter)))
|
||||
empty-seq))
|
||||
|
||||
(defn lazy2iter
|
||||
"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. Same is true for iterators
|
||||
|
||||
(defn filter2 [pred coll]
|
||||
(tail (iter2lazy (filter pred coll))))
|
||||
(defn filter2 [pred coll] (iter2lazy (filter pred coll)))
|
||||
|
||||
(def arr [0 -1 -2 33 -3 0 302 -3 2 8 54 3 -2 0])
|
||||
|
||||
|
@ -379,7 +379,7 @@ If no match is found, returns nil"
|
||||
|
||||
(defmacro when-let
|
||||
"Takes the first one or two forms in vector and if true binds
|
||||
all the forms with let and evaluates body"
|
||||
all the forms with let and evaluates the body"
|
||||
[bindings & body]
|
||||
(def head (ast-unwrap1 bindings))
|
||||
(tuple 'let head
|
||||
@ -403,21 +403,21 @@ If no match is found, returns nil"
|
||||
(array-slice functions 5 -1)))))
|
||||
|
||||
(defn zipcoll
|
||||
"Creates an table or tuple from two arrays/tuples. Result is table if no
|
||||
third argument is given"
|
||||
"Creates an table or tuple from two arrays/tuples. If a third argument of
|
||||
:struct is givent resault is struct else is table."
|
||||
[coll-1 coll-2 the-type]
|
||||
(var zipping-table @{})
|
||||
(def {:more more1 :next next1} (iter coll-1))
|
||||
(def {:more more2 :next next2} (iter coll-2))
|
||||
(while (and (more1) (more2))
|
||||
(put zipping-table (next1) (next2)))
|
||||
(if (= :struct the-type)
|
||||
(if (struct? the-type)
|
||||
(table-to-struct zipping-table)
|
||||
zipping-table))
|
||||
|
||||
(defn update
|
||||
"Accepts a key argument and passes its associated value to a function.
|
||||
The key, then is associated to that value"
|
||||
"Accepts a key argument and passes its' associated value to a function.
|
||||
The key then, is associated to the function's return value"
|
||||
[coll a-key a-function & args]
|
||||
(def old-value (get coll a-key) )
|
||||
(put coll a-key (apply a-function old-value args)))
|
||||
|
@ -614,7 +614,7 @@ DstSlot dstc_fn(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Keep in lexographic order */
|
||||
/* Keep in lexicographic order */
|
||||
static const DstSpecial dstc_specials[] = {
|
||||
{":=", dstc_varset},
|
||||
{"ast-quote", dstc_astquote},
|
||||
|
Loading…
Reference in New Issue
Block a user