From 6971eedee776d0014c94cbee519655e37707a8f7 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Wed, 30 Aug 2023 19:33:12 +0300 Subject: rename the lazy-seq function to lazy-seq* to avoid name clash with a macro --- cljlib.fnl | 9 +++++---- doc/cljlib.md | 13 +++++++++++++ src/cljlib.fnl | 9 +++++---- tasks/build | 19 +++++++++++++++++++ tasks/run-tests | 10 ++++++++++ utils/build | 19 ------------------- utils/run-tests | 10 ---------- 7 files changed, 52 insertions(+), 37 deletions(-) create mode 100644 tasks/build create mode 100644 tasks/run-tests delete mode 100644 utils/build delete mode 100644 utils/run-tests diff --git a/cljlib.fnl b/cljlib.fnl index dd6c621..1981fad 100644 --- a/cljlib.fnl +++ b/cljlib.fnl @@ -3615,10 +3615,11 @@ Lua `#` operator on `rev` takes linar time. If `t` is empty returns [rev] (seq* (lazy.rseq rev))) -(defn lazy-seq +(defn lazy-seq* "Create lazy sequence from the result of calling a function `f`. Delays execution of `f` until sequence is consumed. `f` must return a -sequence or a vector." +sequence or a vector. There's a convenience macro `lazy-seq' +automates the process of function creation." [f] (seq* (lazy.lazy-seq f))) @@ -4535,7 +4536,7 @@ number-of-colls arguments" (if-some [s (seq coll)] (let [res (f nil (first s))] (cond (reduced? res) (f (deref res)) - (seq? res) (concat res (lazy-seq #(step (rest s)))) + (seq? res) (concat res (lazy-seq* #(step (rest s)))) :else (step (rest s)))) (f nil))) coll) @@ -4546,7 +4547,7 @@ number-of-colls arguments" (if (every? seq colls) (let [res (apply f nil (map first colls))] (cond (reduced? res) (f (deref res)) - (seq? res) (concat res (lazy-seq #(step (map rest colls)))) + (seq? res) (concat res (lazy-seq* #(step (map rest colls)))) :else (step (map rest colls)))) (f nil))) (cons coll colls)) diff --git a/doc/cljlib.md b/doc/cljlib.md index b1678f5..d118652 100644 --- a/doc/cljlib.md +++ b/doc/cljlib.md @@ -154,6 +154,7 @@ Another difference is that Lua 5.2 and LuaJIT don't have an inbuilt UTF-8 librar - [`iterate`](#iterate) - [`keep`](#keep) - [`keep-indexed`](#keep-indexed) +- [`lazy-seq*`](#lazy-seq-1) - [`line-seq`](#line-seq) - [`list`](#list) - [`list*`](#list-1) @@ -2052,6 +2053,18 @@ the `coll`. Note, this means false return values will be included. `f` must be free of side effects. Returns a transducer when no collection is provided. +## `lazy-seq*` +Function signature: + +``` +(lazy-seq* [f]) +``` + +Create lazy sequence from the result of calling a function `f`. +Delays execution of `f` until sequence is consumed. `f` must return a +sequence or a vector. There's a convenience macro [`lazy-seq`](#lazy-seq) +automates the process of function creation. + ## `line-seq` Function signature: diff --git a/src/cljlib.fnl b/src/cljlib.fnl index df63e4f..1629a6f 100644 --- a/src/cljlib.fnl +++ b/src/cljlib.fnl @@ -1778,10 +1778,11 @@ Lua `#` operator on `rev` takes linar time. If `t` is empty returns [rev] (seq* (lazy.rseq rev))) -(defn lazy-seq +(defn lazy-seq* "Create lazy sequence from the result of calling a function `f`. Delays execution of `f` until sequence is consumed. `f` must return a -sequence or a vector." +sequence or a vector. There's a convenience macro `lazy-seq' +automates the process of function creation." [f] (seq* (lazy.lazy-seq f))) @@ -2698,7 +2699,7 @@ number-of-colls arguments" (if-some [s (seq coll)] (let [res (f nil (first s))] (cond (reduced? res) (f (deref res)) - (seq? res) (concat res (lazy-seq #(step (rest s)))) + (seq? res) (concat res (lazy-seq* #(step (rest s)))) :else (step (rest s)))) (f nil))) coll) @@ -2709,7 +2710,7 @@ number-of-colls arguments" (if (every? seq colls) (let [res (apply f nil (map first colls))] (cond (reduced? res) (f (deref res)) - (seq? res) (concat res (lazy-seq #(step (map rest colls)))) + (seq? res) (concat res (lazy-seq* #(step (map rest colls)))) :else (step (map rest colls)))) (f nil))) (cons coll colls)) diff --git a/tasks/build b/tasks/build new file mode 100644 index 0000000..b1fa0eb --- /dev/null +++ b/tasks/build @@ -0,0 +1,19 @@ +;; -*- mode: fennel; -*- vi:ft=fennel + +(fn spit-lib [path to] + (with-open [lib (io.open path)] + (each [line (lib:lines)] + ;; patching compile-time variable used to store macro module + ;; namr because when loafing the combined file it will always + ;; equal the the main module and will break macros in vendored + ;; libraries. + (case (line:match "%(local lib%-name %(or %.%.%. (.*)") + name (to:write (.. "(local lib-name (or " name "\n")) + _ (to:write line "\n"))))) + +(with-open [cljlib (io.open "./cljlib.fnl" :w)] + (let [main (io.open "src/cljlib.fnl")] + (each [line (main:lines)] + (case (line:match ";;;###include (.*)") + (path) (spit-lib path cljlib) + _ (cljlib:write line "\n"))))) diff --git a/tasks/run-tests b/tasks/run-tests new file mode 100644 index 0000000..63a43d7 --- /dev/null +++ b/tasks/run-tests @@ -0,0 +1,10 @@ +;; -*- mode: fennel; -*- vi:ft=fennel + +(local t (require :fennel-test.fennel-test)) + +(local test-modules + [:tests.core + :tests.fn + :tests.macros]) + +(t.run-tests test-modules) diff --git a/utils/build b/utils/build deleted file mode 100644 index b1fa0eb..0000000 --- a/utils/build +++ /dev/null @@ -1,19 +0,0 @@ -;; -*- mode: fennel; -*- vi:ft=fennel - -(fn spit-lib [path to] - (with-open [lib (io.open path)] - (each [line (lib:lines)] - ;; patching compile-time variable used to store macro module - ;; namr because when loafing the combined file it will always - ;; equal the the main module and will break macros in vendored - ;; libraries. - (case (line:match "%(local lib%-name %(or %.%.%. (.*)") - name (to:write (.. "(local lib-name (or " name "\n")) - _ (to:write line "\n"))))) - -(with-open [cljlib (io.open "./cljlib.fnl" :w)] - (let [main (io.open "src/cljlib.fnl")] - (each [line (main:lines)] - (case (line:match ";;;###include (.*)") - (path) (spit-lib path cljlib) - _ (cljlib:write line "\n"))))) diff --git a/utils/run-tests b/utils/run-tests deleted file mode 100644 index 63a43d7..0000000 --- a/utils/run-tests +++ /dev/null @@ -1,10 +0,0 @@ -;; -*- mode: fennel; -*- vi:ft=fennel - -(local t (require :fennel-test.fennel-test)) - -(local test-modules - [:tests.core - :tests.fn - :tests.macros]) - -(t.run-tests test-modules) -- cgit v1.2.3