From d9105299f10f33ed332c8d950a43f7051434ec22 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 25 Nov 2025 19:36:56 -0600 Subject: [PATCH] Allow matching tuples and arrays exactly via a dollar suffix. --- CHANGELOG.md | 4 ++++ src/boot/boot.janet | 44 ++-------------------------------------- test/suite-corelib.janet | 6 ++++++ 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c46147a6..9ceb7c8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## Unreleased - ??? +- Add `thaw-keep-keys` as a variant of thaw +- The `repl` function now respects the `*repl-prompt*` dynamic binding. + ## 1.40.1 - 2025-11-16 - Fix `JANET_REDUCED_OS` build regression caused by `os/posix-chroot`. - Code formatting diff --git a/src/boot/boot.janet b/src/boot/boot.janet index f46e576d..9b46b4d7 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1480,52 +1480,12 @@ ``Do a post-order traversal of a data structure and call `(f x)` on every visitation.`` [f form] - (f (walk (fn :visit [x] (postwalk f x)) form))) + (f (walk (fn [x] (postwalk f x)) form))) (defn prewalk "Similar to `postwalk`, but do pre-order traversal." [f form] - (walk (fn :visit [x] (prewalk f x)) (f form))) - -(defn- walk-dict-pairs [f form] - (def ret @{}) - (eachp p1 form - (def p2 (f p1)) - (when p2 - (def [k v] p2) - (put ret k v))) - ret) - -(defn walk2 - ``Iterate over the values in ast and apply `f` - to them. Collect the results in a data structure. Differs from `walk` in 2 ways: - - * Will iterate fibers and gather results into an array. - * Tables and structs are traversed by visiting each key-value as a tuple instead - of iterating them in an interleaved fashion. - - If ast is not a - table, struct, array, tuple, or fiber, - returns form.`` - [f form] - (case (type form) - :table (walk-dict-pairs f form) - :struct (table/to-struct (walk-dict-pairs f form)) - :array (walk-ind f form) - :tuple (keep-syntax! form (walk-ind f form)) - :fiber (walk-ind f form) - form)) - -(defn postwalk2 - ``Do a post-order traversal of a data structure and call `(f x)` - on every visitation.`` - [f form] - (f (walk2 (fn :visit [x] (postwalk2 f x)) form))) - -(defn prewalk2 - "Similar to `postwalk`, but do pre-order traversal." - [f form] - (walk2 (fn :visit [x] (prewalk2 f x)) (f form))) + (walk (fn [x] (prewalk f x)) (f form))) (defmacro as-> ``Thread forms together, replacing `as` in `forms` with the value diff --git a/test/suite-corelib.janet b/test/suite-corelib.janet index d2a5d4d5..3008ef3d 100644 --- a/test/suite-corelib.janet +++ b/test/suite-corelib.janet @@ -185,5 +185,11 @@ (assert-no-error "iterate over coro 2" (keys (generate [x :range [0 10]] x))) (assert-no-error "iterate over coro 3" (pairs (generate [x :range [0 10]] x))) +# thaw +(def ds1 [1 2 3 {:a 2} {:b 3} 4 5 6]) +(def ds2 [1 2 3 {:a 2 {:c :d} {:e :f}} {:b 3} 4 5 6]) +(assert (deep= (thaw ds1) (thaw-keep-keys ds1)) "thaw vs. thaw-keep-keys 1") +(assert (deep-not= (thaw ds2) (thaw-keep-keys ds2)) "thaw vs. thaw-keep-keys 2") + (end-suite)