diff --git a/CHANGELOG.md b/CHANGELOG.md index ea45911b..f3e3caa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## 1.23.1 - ??? +- Improve default error message from `assert`. +- Add the `tabseq` macro for simpler table comprehensions. - Allow setting `(dyn :task-id)` in fibers to improve context in supervisor messages. Prior to this change, supverisor messages over threaded channels would be from ambiguous threads/fibers. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 1c42e6ea..ae6415c5 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -158,7 +158,7 @@ (def ,v ,x) (if ,v ,v - (,error ,(if err err "assert failure"))))) + (,error ,(if err err (string/format "assert failure in %j" x)))))) (defn errorf "A combination of `error` and `string/format`. Equivalent to `(error (string/format fmt ;args))`." @@ -606,13 +606,20 @@ See `loop` for details.`` [head & body] (def $accum (gensym)) - ~(do (def ,$accum @[]) (loop ,head (array/push ,$accum (do ,;body))) ,$accum)) + ~(do (def ,$accum @[]) (loop ,head (,array/push ,$accum (do ,;body))) ,$accum)) + +(defmacro tabseq + ``Similar to `loop`, but accumulates key value pairs into a table. + See `loop` for details.`` + [head key-body & value-body] + (def $accum (gensym)) + ~(do (def ,$accum @{}) (loop ,head (,put ,$accum ,key-body (do ,;value-body))) ,$accum)) (defmacro generate ``Create a generator expression using the `loop` syntax. Returns a fiber that yields all values inside the loop in order. See `loop` for details.`` [head & body] - ~(fiber/new (fn [] (loop ,head (yield (do ,;body)))) :yi)) + ~(,fiber/new (fn [] (loop ,head (yield (do ,;body)))) :yi)) (defmacro coro "A wrapper for making fibers that may yield multiple values (coroutine). Same as `(fiber/new (fn [] ;body) :yi)`." @@ -2768,13 +2775,13 @@ (def c ((:where p) 0)) (def prpt (string "debug[" level "]:" c ":" status "> ")) (getline prpt buf nextenv)) - (print "entering debug[" level "] - (quit) to exit") + (eprint "entering debug[" level "] - (quit) to exit") (flush) (run-context {:chunks debugger-chunks :on-status (debugger-on-status-var nextenv (+ 1 level) true) :env nextenv}) - (print "exiting debug[" level "]") + (eprint "exiting debug[" level "]") (flush) (nextenv :resume-value)) diff --git a/src/core/pp.c b/src/core/pp.c index 1a7ad6a1..af28091e 100644 --- a/src/core/pp.c +++ b/src/core/pp.c @@ -762,8 +762,7 @@ static const char *scanformat( memset(precision, '\0', 3); while (*p != '\0' && strchr(FMT_FLAGS, *p) != NULL) p++; /* skip flags */ - if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS) / sizeof(char)) - janet_panic("invalid format (repeated flags)"); + if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS)) janet_panic("invalid format (repeated flags)"); if (isdigit((int)(*p))) width[0] = *p++; /* skip width */ if (isdigit((int)(*p))) diff --git a/src/core/string.c b/src/core/string.c index e283ead0..632f7a50 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -530,7 +530,7 @@ JANET_CORE_FN(cfun_string_join, JANET_CORE_FN(cfun_string_format, "(string/format format & values)", - "Similar to `snprintf`, but specialized for operating with Janet values. Returns " + "Similar to C's `snprintf`, but specialized for operating with Janet values. Returns " "a new string.") { janet_arity(argc, 1, -1); JanetBuffer *buffer = janet_buffer(0);