Add some library functions and add newline character to reading line

from file.
This commit is contained in:
bakpakin 2018-02-06 10:31:42 -05:00
parent c76b08cecc
commit 7bfb3145cb
2 changed files with 32 additions and 4 deletions

View File

@ -130,3 +130,33 @@
(fn [x] (print (pp1 @{} @"" x)))
))
(defn pairs [x]
(var lastkey (next x nil))
{
:more (fn [] lastkey)
:next (fn []
(def ret (tuple lastkey (get x lastkey)))
(varset! lastkey (next x lastkey))
ret)
})
(defn keys [x]
(var lastkey (next x nil))
{
:more (fn [] lastkey)
:next (fn []
(def ret lastkey)
(varset! lastkey (next x lastkey))
ret)
})
(defn values [x]
(var lastkey (next x nil))
{
:more (fn [] lastkey)
:next (fn []
(def ret (get x lastkey))
(varset! lastkey (next x lastkey))
ret)
})

View File

@ -187,10 +187,8 @@ static int dst_io_fread(DstArgs args) {
} else if (!dst_cstrcmp(sym, ":line")) {
for (;;) {
int x = fgetc(iof->file);
if (x == EOF || x == '\n') {
break;
}
if (dst_buffer_push_u8(b, (uint8_t)x)) return dst_throw(args, "buffer overflow");
if (x != EOF && dst_buffer_push_u8(b, (uint8_t)x)) return dst_throw(args, "buffer overflow");
if (x == EOF || x == '\n') break;
}
return dst_return(args, dst_wrap_buffer(b));
} else {