mirror of
https://github.com/janet-lang/janet
synced 2024-11-24 17:27:18 +00:00
Add tabseq
macro.
This commit is contained in:
parent
f456369941
commit
9bde57854a
@ -2,6 +2,8 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## 1.23.1 - ???
|
## 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
|
- 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.
|
this change, supverisor messages over threaded channels would be from ambiguous threads/fibers.
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@
|
|||||||
(def ,v ,x)
|
(def ,v ,x)
|
||||||
(if ,v
|
(if ,v
|
||||||
,v
|
,v
|
||||||
(,error ,(if err err "assert failure")))))
|
(,error ,(if err err (string/format "assert failure in %j" x))))))
|
||||||
|
|
||||||
(defn errorf
|
(defn errorf
|
||||||
"A combination of `error` and `string/format`. Equivalent to `(error (string/format fmt ;args))`."
|
"A combination of `error` and `string/format`. Equivalent to `(error (string/format fmt ;args))`."
|
||||||
@ -606,13 +606,20 @@
|
|||||||
See `loop` for details.``
|
See `loop` for details.``
|
||||||
[head & body]
|
[head & body]
|
||||||
(def $accum (gensym))
|
(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
|
(defmacro generate
|
||||||
``Create a generator expression using the `loop` syntax. Returns a fiber
|
``Create a generator expression using the `loop` syntax. Returns a fiber
|
||||||
that yields all values inside the loop in order. See `loop` for details.``
|
that yields all values inside the loop in order. See `loop` for details.``
|
||||||
[head & body]
|
[head & body]
|
||||||
~(fiber/new (fn [] (loop ,head (yield (do ,;body)))) :yi))
|
~(,fiber/new (fn [] (loop ,head (yield (do ,;body)))) :yi))
|
||||||
|
|
||||||
(defmacro coro
|
(defmacro coro
|
||||||
"A wrapper for making fibers that may yield multiple values (coroutine). Same as `(fiber/new (fn [] ;body) :yi)`."
|
"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 c ((:where p) 0))
|
||||||
(def prpt (string "debug[" level "]:" c ":" status "> "))
|
(def prpt (string "debug[" level "]:" c ":" status "> "))
|
||||||
(getline prpt buf nextenv))
|
(getline prpt buf nextenv))
|
||||||
(print "entering debug[" level "] - (quit) to exit")
|
(eprint "entering debug[" level "] - (quit) to exit")
|
||||||
(flush)
|
(flush)
|
||||||
(run-context
|
(run-context
|
||||||
{:chunks debugger-chunks
|
{:chunks debugger-chunks
|
||||||
:on-status (debugger-on-status-var nextenv (+ 1 level) true)
|
:on-status (debugger-on-status-var nextenv (+ 1 level) true)
|
||||||
:env nextenv})
|
:env nextenv})
|
||||||
(print "exiting debug[" level "]")
|
(eprint "exiting debug[" level "]")
|
||||||
(flush)
|
(flush)
|
||||||
(nextenv :resume-value))
|
(nextenv :resume-value))
|
||||||
|
|
||||||
|
@ -762,8 +762,7 @@ static const char *scanformat(
|
|||||||
memset(precision, '\0', 3);
|
memset(precision, '\0', 3);
|
||||||
while (*p != '\0' && strchr(FMT_FLAGS, *p) != NULL)
|
while (*p != '\0' && strchr(FMT_FLAGS, *p) != NULL)
|
||||||
p++; /* skip flags */
|
p++; /* skip flags */
|
||||||
if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS) / sizeof(char))
|
if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS)) janet_panic("invalid format (repeated flags)");
|
||||||
janet_panic("invalid format (repeated flags)");
|
|
||||||
if (isdigit((int)(*p)))
|
if (isdigit((int)(*p)))
|
||||||
width[0] = *p++; /* skip width */
|
width[0] = *p++; /* skip width */
|
||||||
if (isdigit((int)(*p)))
|
if (isdigit((int)(*p)))
|
||||||
|
@ -530,7 +530,7 @@ JANET_CORE_FN(cfun_string_join,
|
|||||||
|
|
||||||
JANET_CORE_FN(cfun_string_format,
|
JANET_CORE_FN(cfun_string_format,
|
||||||
"(string/format format & values)",
|
"(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.") {
|
"a new string.") {
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetBuffer *buffer = janet_buffer(0);
|
JanetBuffer *buffer = janet_buffer(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user