diff --git a/src/compiler/boot.dst b/src/compiler/boot.dst index b4c8a0ae..bc25bf03 100644 --- a/src/compiler/boot.dst +++ b/src/compiler/boot.dst @@ -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) + }) diff --git a/src/core/io.c b/src/core/io.c index 643dccc4..a47cbb0d 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -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 {