summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Listopadov <andreyorst@gmail.com>2021-07-22 22:35:49 +0300
committerAndrey Listopadov <andreyorst@gmail.com>2021-07-22 22:40:04 +0300
commit859cf1388770f65d31002d3667977d6760c2e092 (patch)
treea5dcc420cc64154c7bc482bfc6370ac8d275fbd4
parentcc82dd57c87e19439f851c2bfd66834f70276bb8 (diff)
release: v0.5.4
-rw-r--r--.fenneldoc4
-rw-r--r--CHANGELOG.md8
-rw-r--r--doc/cljlib.md5
-rw-r--r--doc/macros.md29
-rw-r--r--init-macros.fnl58
-rw-r--r--tests/core.fnl1
-rw-r--r--tests/fn.fnl40
-rw-r--r--tests/macros.fnl19
8 files changed, 71 insertions, 93 deletions
diff --git a/.fenneldoc b/.fenneldoc
index 058a631..bd1ce89 100644
--- a/.fenneldoc
+++ b/.fenneldoc
@@ -1,5 +1,5 @@
;; -*- mode: fennel; -*- vi:ft=fennel
-;; Configuration file for Fenneldoc v0.1.5
+;; Configuration file for Fenneldoc v0.1.6
;; https://gitlab.com/andreyorst/fenneldoc
{:fennel-path {}
@@ -32,7 +32,7 @@
:project-copyright "Copyright (C) 2020-2021 Andrey Listopadov"
:project-doc-order {}
:project-license "[MIT](https://gitlab.com/andreyorst/fennel-cljlib/-/raw/master/LICENSE)"
- :project-version "v0.5.3"
+ :project-version "v0.5.4"
:sandbox true
:test-requirements {:init-macros.fnl "(require-macros :init-macros)
(import-macros {: assert-eq} :fennel-test.test)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa03491..5553189 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+## Cljlib v0.5.4 (2021-07-22)
+
+- Remove `when-meta` macro.
+- Add `loop` macro.
+- Add `defn` as an alias to `fn*`.
+- Make `fn*` always set the metadata.
+- Fix `catch` in `try` not returning multiple values.
+
## Cljlib v0.5.3 (2021-04-24)
- test library is now external dependency.
diff --git a/doc/cljlib.md b/doc/cljlib.md
index 9d23746..6d7acc1 100644
--- a/doc/cljlib.md
+++ b/doc/cljlib.md
@@ -1,4 +1,4 @@
-# Cljlib (v0.5.3)
+# Cljlib (v0.5.4)
Fennel-cljlib - functions from Clojure's core.clj implemented on top
of Fennel.
@@ -935,6 +935,7 @@ Returns the nth rest of `col`, `col` when `n` is 0.
(assert-eq (nthrest [1 2 3 4] 0) [1 2 3 4])
```
+
## `partition`
Function signature:
@@ -1258,5 +1259,5 @@ Copyright (C) 2020-2021 Andrey Listopadov
License: [MIT](https://gitlab.com/andreyorst/fennel-cljlib/-/raw/master/LICENSE)
-<!-- Generated with Fenneldoc v0.1.5
+<!-- Generated with Fenneldoc v0.1.6
https://gitlab.com/andreyorst/fenneldoc -->
diff --git a/doc/macros.md b/doc/macros.md
index 6f90328..c90d0af 100644
--- a/doc/macros.md
+++ b/doc/macros.md
@@ -1,9 +1,9 @@
-# Macros (v0.5.3)
+# Macros (v0.5.4)
Macros for Cljlib that implement various facilities from Clojure.
**Table of contents**
-- [`fn*`](#fn)
+- [`fn*`, `defn`](#fn-defn)
- [`try`](#try)
- [`def`](#def)
- [`defonce`](#defonce)
@@ -11,7 +11,6 @@ Macros for Cljlib that implement various facilities from Clojure.
- [`defmethod`](#defmethod)
- [`into`](#into)
- [`empty`](#empty)
-- [`when-meta`](#when-meta)
- [`with-meta`](#with-meta)
- [`meta`](#meta)
- [`if-let`](#if-let)
@@ -20,7 +19,7 @@ Macros for Cljlib that implement various facilities from Clojure.
- [`when-some`](#when-some)
- [`loop`](#loop)
-## `fn*`
+## `fn*`, `defn`
Function signature:
```
@@ -476,19 +475,6 @@ and return result of the same type:
```
See [`into`](#into) for more info on how conversion is done.
-## `when-meta`
-Function signature:
-
-```
-(when-meta [& body])
-```
-
-Wrapper that compiles away if metadata support was not enabled.
-What this effectively means, is that everything that is wrapped with
-this macro and its `body` will disappear from the resulting Lua code
-if metadata is not enabled when compiling with `fennel --compile`
-without `--metadata` switch.
-
## `with-meta`
Function signature:
@@ -496,8 +482,7 @@ Function signature:
(with-meta value meta)
```
-Attach [`meta`](#meta) to a `value`. When metadata feature is not enabled,
-returns the value without additional metadata.
+Attach [`meta`](#meta) to a `value`.
``` fennel
(local foo (with-meta (fn [...] (let [[x y z] [...]] (+ x y z)))
@@ -515,8 +500,7 @@ Function signature:
(meta value)
```
-Get `value` metadata. If value has no metadata, or metadata
-feature is not enabled returns `nil`.
+Get `value` metadata. If value has no metadata returns `nil`.
### Example
@@ -624,6 +608,7 @@ iteration), and with `i` being called with one value greater than the previous.
When the loop terminates (When the user doesn't call `recur`) it will return the
number of elements in the passed in table. (In this case, 5)
+
---
Copyright (C) 2020-2021 Andrey Listopadov
@@ -631,5 +616,5 @@ Copyright (C) 2020-2021 Andrey Listopadov
License: [MIT](https://gitlab.com/andreyorst/fennel-cljlib/-/raw/master/LICENSE)
-<!-- Generated with Fenneldoc v0.1.5
+<!-- Generated with Fenneldoc v0.1.6
https://gitlab.com/andreyorst/fenneldoc -->
diff --git a/init-macros.fnl b/init-macros.fnl
index 3f3ab24..0b5fe65 100644
--- a/init-macros.fnl
+++ b/init-macros.fnl
@@ -151,25 +151,8 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; compile time check that `--metadata` feature was enabled
-(local meta-enabled (pcall _SCOPE.specials.doc
- (list (sym :doc) (sym :doc))
- _SCOPE _CHUNK))
-
-(fn when-meta [...]
- "Wrapper that compiles away if metadata support was not enabled.
-What this effectively means, is that everything that is wrapped with
-this macro and its `body' will disappear from the resulting Lua code
-if metadata is not enabled when compiling with `fennel --compile'
-without `--metadata` switch."
- (when meta-enabled
- `(do ,...)))
-
-(attach-meta when-meta {:fnl/arglist ["[& body]"]})
-
(fn meta [value]
- "Get `value' metadata. If value has no metadata, or metadata
-feature is not enabled returns `nil'.
+ "Get `value' metadata. If value has no metadata returns `nil'.
# Example
@@ -198,13 +181,11 @@ Lastly, note that prior to Fennel 0.7.1 `import-macros' wasn't
respecting `--metadata` switch. So if you're using Fennel < 0.7.1
this stuff will only work if you use `require-macros' instead of
`import-macros'."
- (when-meta
- `(let [(res# fennel#) (pcall require :fennel)]
- (if res# (. fennel#.metadata ,value)))))
+ `(let [(res# fennel#) (pcall require :fennel)]
+ (if res# (. fennel#.metadata ,value))))
(fn with-meta [value meta]
- "Attach `meta' to a `value'. When metadata feature is not enabled,
-returns the value without additional metadata.
+ "Attach `meta' to a `value'.
``` fennel
(local foo (with-meta (fn [...] (let [[x y z] [...]] (+ x y z)))
@@ -214,13 +195,12 @@ returns the value without additional metadata.
;; => (foo x y z ...)
;; => sum first three values
```"
- (if (not meta-enabled) value
- `(let [value# ,value
- (res# fennel#) (pcall require :fennel)]
- (if res#
- (each [k# v# (pairs ,meta)]
- (fennel#.metadata:set value# k# v#)))
- value#)))
+ `(let [value# ,value
+ (res# fennel#) (pcall require :fennel)]
+ (if res#
+ (each [k# v# (pairs ,meta)]
+ (fennel#.metadata:set value# k# v#)))
+ value#))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fn* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -559,9 +539,13 @@ from `ns.strings', so the latter must be fully qualified
(if namespaced?
`(local ,name-wo-namespace
(do (set ,name (fn ,name-wo-namespace [...] ,docstring ,body)) ;; set function into module table, e.g. (set foo.bar bar)
- ,(with-meta name-wo-namespace `{:fnl/arglist ,arglist-doc})))
- `(local ,name ,(with-meta `(fn ,name [...] ,docstring ,body) `{:fnl/arglist ,arglist-doc})))
- (with-meta `(fn [...] ,docstring ,body) `{:fnl/arglist ,arglist-doc}))))
+ ,(with-meta name `{:fnl/arglist ,arglist-doc
+ :fnl/docstring ,docstring})))
+ `(local ,name ,(with-meta `(fn ,name [...] ,docstring ,body)
+ `{:fnl/arglist ,arglist-doc
+ :fnl/docstring ,docstring})))
+ (with-meta `(fn [...] ,docstring ,body) `{:fnl/arglist ,arglist-doc
+ :fnl/docstring ,docstring}))))
(attach-meta fn* {:fnl/arglist ["name" "docstring?" "([arglist*] body)*"]})
@@ -1096,9 +1080,10 @@ Checks if there already was `finally' clause met."
(when (sym? binding-or-val)
(set add-catchall? false))
(table.insert clauses `(false ,binding-or-val))
- (table.insert clauses `(let [res# (do ,((or table.unpack _G.unpack) body))]
+ (table.insert clauses `(let [res# ((or table.pack #(doto [$...] (tset :n (select :# $...))))
+ (do ,((or table.unpack _G.unpack) body)))]
,(. finally 1)
- res#)))
+ (table.unpack res# 1 res#.n))))
(when add-catchall?
;; implicit catchall which retrows error further is added only
;; if there were no catch clause that used symbol as catch value
@@ -1276,7 +1261,6 @@ number of elements in the passed in table. (In this case, 5)"
: when-some
: empty
: into
- : when-meta
: with-meta
: meta
: defmulti
@@ -1290,7 +1274,7 @@ number of elements in the passed in table. (In this case, 5)"
:try
:def :defonce :defmulti :defmethod
:into :empty
- :when-meta :with-meta :meta
+ :with-meta :meta
:if-let :when-let :if-some :when-some]
:_DESCRIPTION "Macros for Cljlib that implement various facilities from Clojure."
:_MODULE_NAME "macros"}})
diff --git a/tests/core.fnl b/tests/core.fnl
index d759fe4..ab3b08a 100644
--- a/tests/core.fnl
+++ b/tests/core.fnl
@@ -446,7 +446,6 @@
(assert-eq (vals {:a 1}) [1])
(match (pcall #(assert-eq (keys {:a 1 :b 2 :c 3}) (hash-set :a :b :c)))
(false msg) (io.stderr:write "WARNING: " msg))
- (print "10")
(match (pcall #(assert-eq (vals {:a 1 :b 2 :c 3}) (hash-set 1 2 3)))
(false msg) (io.stderr:write "WARNING: " msg))
(assert-eq (find {:a 1 :b 2 :c 3} :c) [:c 3])
diff --git a/tests/fn.fnl b/tests/fn.fnl
index 3517918..36fd395 100644
--- a/tests/fn.fnl
+++ b/tests/fn.fnl
@@ -7,56 +7,56 @@
"docstring"
[x] x)
(assert-eq (meta f)
- (when-meta {:fnl/docstring "docstring"
- :fnl/arglist ["([x])"]}))
+ {:fnl/docstring "docstring"
+ :fnl/arglist ["([x])"]})
(fn* f
"docstring"
[])
(assert-eq (meta f)
- (when-meta {:fnl/docstring "docstring"
- :fnl/arglist ["([])"]}))
+ {:fnl/docstring "docstring"
+ :fnl/arglist ["([])"]})
(fn* f
"docstring"
([x] x))
(assert-eq (meta f)
- (when-meta {:fnl/docstring "docstring"
- :fnl/arglist ["([x])"]}))
+ {:fnl/docstring "docstring"
+ :fnl/arglist ["([x])"]})
(fn* f
"docstring"
([x] x)
([x y] (+ x y)))
(assert-eq (meta f)
- (when-meta {:fnl/docstring "docstring"
- :fnl/arglist ["([x])"
- "([x y])"]}))
+ {:fnl/docstring "docstring"
+ :fnl/arglist ["([x])"
+ "([x y])"]})
(fn* f
"docstring"
([])
([x y] (+ x y)))
(assert-eq (meta f)
- (when-meta {:fnl/docstring "docstring"
- :fnl/arglist ["([])"
- "([x y])"]}))
+ {:fnl/docstring "docstring"
+ :fnl/arglist ["([])"
+ "([x y])"]})
(fn* f
"docstring"
([x] x)
([x y] (+ x y))
([x y & z] (+ x y)))
(assert-eq (meta f)
- (when-meta {:fnl/docstring "docstring"
- :fnl/arglist ["([x])"
- "([x y])"
- "([x y & z])"]})))
+ {:fnl/docstring "docstring"
+ :fnl/arglist ["([x])"
+ "([x y])"
+ "([x y & z])"]}))
(testing "fn* doc destructuring"
(fn* f [[a b c]])
(assert-eq (meta f)
- (when-meta {:fnl/arglist ["([[a b c]])"]}))
+ {:fnl/arglist ["([[a b c]])"]})
(fn* f ([[a b c]]) ([{: a}]) ([[{:a [a b c]}]]))
(assert-eq (meta f)
- (when-meta {:fnl/arglist ["([[a b c]])"
- "([{:a a}])"
- "([[{:a [a b c]}]])"]})))
+ {:fnl/arglist ["([[a b c]])"
+ "([{:a a}])"
+ "([[{:a [a b c]}]])"]}))
(testing "fn* methods"
(local ns {:a 1 :b 2})
diff --git a/tests/macros.fnl b/tests/macros.fnl
index cf5c09b..50961d6 100644
--- a/tests/macros.fnl
+++ b/tests/macros.fnl
@@ -128,9 +128,9 @@
(testing "defmulti docstring"
(defmulti f "documentation" (fn [x] x))
- (assert-eq (meta f) (when-meta {:fnl/docstring "documentation"}))
+ (assert-eq (meta f) {:fnl/docstring "documentation"})
(defmulti g "documentation" (fn [x] x) :default 0)
- (assert-eq (meta g) (when-meta {:fnl/docstring "documentation"})))
+ (assert-eq (meta g) {:fnl/docstring "documentation"}))
(testing "defmulti with multiple arity"
(defmulti f (fn* ([x] x) ([x y] [x y])))
@@ -170,21 +170,21 @@
(deftest meta
(testing "with-meta"
- (assert-eq (meta (with-meta :a {:k :v})) (when-meta {:k :v})))
+ (assert-eq (meta (with-meta :a {:k :v})) {:k :v}))
(testing "def meta"
(def {:doc "x"} x 10)
- (assert-eq (meta x) (when-meta {:fnl/docstring "x"}))
+ (assert-eq (meta x) {:fnl/docstring "x"})
(def {:doc "x" :mutable true} x 10)
- (assert-eq (meta x) (when-meta {:fnl/docstring "x"})))
+ (assert-eq (meta x) {:fnl/docstring "x"}))
(testing "defonce meta table"
(defonce {:doc "x"} x 10)
- (assert-eq (meta x) (when-meta {:fnl/docstring "x"}))
+ (assert-eq (meta x) {:fnl/docstring "x"})
(defonce {:doc "y"} x 20)
- (assert-eq (meta x) (when-meta {:fnl/docstring "x"}))
+ (assert-eq (meta x) {:fnl/docstring "x"})
(defonce {:doc "y" :mutable true} y 20)
- (assert-eq (meta y) (when-meta {:fnl/docstring "y"}))))
+ (assert-eq (meta y) {:fnl/docstring "y"})))
(deftest empty
(testing "empty map"
@@ -246,7 +246,8 @@
(testing "multi-value results"
(assert-eq 3 (select :# (try (values 1 2 3))))
(assert-eq [1 2 3] [(try (values 1 2 3))])
- (assert-eq 6 (select :# (try (values 1 nil 3 nil nil nil))))))
+ (assert-eq 6 (select :# (try (values 1 nil 3 nil nil nil))))
+ (assert-eq 6 (select :# (try (error 10) (catch _ (values 1 nil 3 nil nil nil)))))))
(deftest loop
(testing "loop macro"