From 44fa0c9514acade4b7dc80be1b1a1dcd5b3b0326 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Mon, 31 Oct 2022 12:47:23 +0300 Subject: fix namespace switching when using then in require-as-include scenarios --- init.fnl | 55 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'init.fnl') diff --git a/init.fnl b/init.fnl index 71b2e19..67bbde7 100644 --- a/init.fnl +++ b/init.fnl @@ -187,7 +187,7 @@ Applying `add` to different amount of arguments: (defn complement "Takes a function `f` and returns the function that takes the same amount of arguments as `f`, has the same effect, and returns the -oppisite truth value." +opposite truth value." [f] (fn* ([] (not (f))) @@ -415,7 +415,7 @@ see `hash-map` for creating tables that have additional metadata attached for this test to work. # Examples -Non empty map: +Non-empty map: ``` fennel (assert-is (map? {:a 1 :b 2})) @@ -445,9 +445,9 @@ Empty tables created with `hash-map` will pass the test: false)) (defn vector? - "Check whether `tbl` is an sequential table. + "Check whether `tbl` is a sequential table. -Non empty sequential tables are tested for two things: +Non-empty sequential tables are tested for two things: - `next` returns the key-value pair, - key, that is returned by the `next` is equal to `1`. @@ -457,7 +457,7 @@ see `vector` for creating tables that have additional metadata attached for this test to work. # Examples -Non empty vector: +Non-empty vector: ``` fennel (assert-is (vector? [1 2 3 4])) @@ -592,7 +592,7 @@ Empty tables created with `vector` will pass the test: (vec* len))))) (defn vector - "Constructs sequential table out of it's arguments. + "Constructs sequential table out of its arguments. Sets additional metadata for function `vector?` to work. @@ -645,10 +645,10 @@ of bounds, `nth` raises an error unless `not-found` is supplied. x) (defn seq - "Construct a sequnce from the given collection `coll`. If `coll` is an -associative table, returns sequence of vectors with key and -value. If `col` is sequential table, returns its shallow copy. If -`col` is string, return sequential table of its codepoints. + "Construct a sequence from the given collection `coll`. If `coll` is +an associative table, returns sequence of vectors with key and value. +If `col` is sequential table, returns its shallow copy. If `col` is +string, return sequential table of its codepoints. # Examples Sequential tables are transformed to sequences: @@ -658,7 +658,7 @@ Sequential tables are transformed to sequences: ``` Associative tables are transformed to format like this `[[key1 value1] -... [keyN valueN]]` and order is non deterministic: +... [keyN valueN]]` and order is non-deterministic: ``` fennel (seq {:a 1 :b 2 :c 3}) ;; @seq([:b 2] [:a 1] [:c 3]) @@ -808,9 +808,9 @@ no collection is provided. (defn mapv "Returns a vector consisting of the result of applying `f` to the set of first items of each `coll`, followed by applying `f` to the set -of second items in each coll, until any one of the `colls` is exhausted. -Any remaining items in other colls are ignored. Function `f` should -accept number-of-colls arguments." +of second items in each coll, until any one of the `colls` is +exhausted. Any remaining items in other collections are ignored. +Function `f` should accept number-of-colls arguments." ([f coll] (->> coll (core.transduce (map f) @@ -822,7 +822,7 @@ accept number-of-colls arguments." (defn map-indexed "Returns a lazy sequence consisting of the result of applying `f` to 1 and the first item of `coll`, followed by applying `f` to 2 and the -second item in `coll`, etc, until `coll` is exhausted. Returns a +second item in `coll`, etc., until `coll` is exhausted. Returns a transducer when no collection is provided." ([f] (fn* [rf] @@ -883,7 +883,8 @@ is provided." (some #(not (pred $)) coll)) (defn range - "Returns lazy sequence of of numbers from `lower` to `upper` with optional `step`." + "Returns lazy sequence of numbers from `lower` to `upper` with optional +`step`." ([] (seq* (lazy.range))) ([upper] (seq* (lazy.range upper))) ([lower upper] (seq* (lazy.range lower upper))) @@ -895,7 +896,7 @@ is provided." (seq* (apply lazy.concat colls))) (defn reverse - "Returns a lazy sequnce with same items as in `coll` but in reverse order." + "Returns a lazy sequence with same items as in `coll` but in reverse order." [coll] (seq* (lazy.reverse coll))) @@ -1052,7 +1053,7 @@ provided." (defn keep-indexed "Returns a lazy sequence of the non-nil results of (f index item) in the `coll`. Note, this means false return values will be included. -`f` must be free of side-effects. Returns a transducer when no +`f` must be free of side effects. Returns a transducer when no collection is provided." ([f] (fn* [rf] @@ -1074,7 +1075,7 @@ collection is provided." items each, at offsets `step` apart. If `step` is not supplied, defaults to `n`, i.e. the partitions do not overlap. If a `pad` collection is supplied, use its elements as necessary to complete last -partition upto `n` items. In case there are not enough padding +partition up to `n` items. In case there are not enough padding elements, return a partition with less than `n` items." ([n coll] (map seq* (lazy.partition n coll))) ([n step coll] (map seq* (lazy.partition n step coll))) @@ -1164,7 +1165,8 @@ per reduce) of `coll` by `f`, starting with `init`." ([f init coll] (seq* (lazy.reductions f init coll)))) (defn contains? - "Test if `elt` is in the `coll`. May be a linear search depending on the type of the collection." + "Test if `elt` is in the `coll`. It may be a linear search depending +on the type of the collection." [coll elt] (lazy.contains? coll elt)) @@ -1246,8 +1248,8 @@ truncated before the file is closed: ```fennel (let [lines (with-open [f (io.open \"init.fnl\" :r)] (line-seq f))] - ;; this errors because only first line was realized, but the file - ;; was closed before the rest of lines were cached + ;; this will error because only first line was realized, but the + ;; file was closed before the rest of lines were cached (assert-not (pcall next lines))) ``` @@ -1414,7 +1416,8 @@ unaffected." (lazy.vals coll))) (defn find - "Returns the map entry for `key`, or `nil` if key not present in `coll`." + "Returns the map entry for `key`, or `nil` if key is not present in +`coll`." [coll key] (assert (or (map? coll) (empty? coll)) "expected a map") (match (. coll key) @@ -1528,7 +1531,7 @@ called. Early termination is supported via `reduced`. applying `f` to `val`, the first key and the first value in `tbl`, then applying `f` to that result and the 2nd key and value, etc. If `tbl` contains no entries, returns `val` and `f` is not called. Note -that reduce-kv is supported on sequential tables and strings, where +that `reduce-kv` is supported on sequential tables and strings, where the keys will be the ordinals. Early termination is possible with the use of `reduced` @@ -1577,7 +1580,7 @@ suitable for transduce by adding an arity-1 signature that calls (defn transduce "`reduce` with a transformation of `f` (`xform`). If `init` is not -supplied, `f` will be called to produce it. f should be a reducing +supplied, `f` will be called to produce it. `f` should be a reducing step function that accepts both 1 and 2 arguments, if it accepts only 2 you can add the arity-1 with `completing`. Returns the result of applying (the transformed) `xform` to `init` and the first item in @@ -2212,7 +2215,7 @@ from `macros.fnl'." multimethod) (defn remove-all-methods - "Removes all of the methods of `multimethod'" + "Removes all methods of `multimethod'" [multimethod] (if (multifn? multimethod) (each [k _ (pairs multimethod)] -- cgit v1.2.3