summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/cljlib.md8
-rw-r--r--doc/macros.md39
2 files changed, 42 insertions, 5 deletions
diff --git a/doc/cljlib.md b/doc/cljlib.md
index 8f6df8b..9d23746 100644
--- a/doc/cljlib.md
+++ b/doc/cljlib.md
@@ -1,4 +1,4 @@
-# Cljlib (0.5.3)
+# Cljlib (v0.5.3)
Fennel-cljlib - functions from Clojure's core.clj implemented on top
of Fennel.
@@ -18,10 +18,10 @@ producing new table and concatenating it with `" "`.
However this library also provides Fennel-specific set of
[macros](./macros.md), that provides additional facilities like
-`fn*` or `defmulti` which extend the language allowing writing code
+`defn` or `defmulti` which extend the language allowing writing code
that looks and works mostly like Clojure.
-Each function in this library is created with `fn*`, which is a
+Each function in this library is created with `defn`, which is a
special macros for creating multi-arity functions. So when you see
function signature like `(foo [x])`, this means that this is function
`foo`, that accepts exactly one argument `x`. In contrary, functions
@@ -844,7 +844,7 @@ Map [`mul`](#mul) over two tables:
Basic `zipmap` implementation:
``` fennel
-(import-macros {: into} :macros)
+(import-macros {: into} :init-macros)
(fn zipmap [keys vals]
(into {} (mapv vector keys vals)))
diff --git a/doc/macros.md b/doc/macros.md
index 6df90fd..6f90328 100644
--- a/doc/macros.md
+++ b/doc/macros.md
@@ -1,4 +1,4 @@
-# Macros.fnl (0.5.3)
+# Macros (v0.5.3)
Macros for Cljlib that implement various facilities from Clojure.
**Table of contents**
@@ -18,6 +18,7 @@ Macros for Cljlib that implement various facilities from Clojure.
- [`when-let`](#when-let)
- [`if-some`](#if-some)
- [`when-some`](#when-some)
+- [`loop`](#loop)
## `fn*`
Function signature:
@@ -587,6 +588,42 @@ If `test` sets `binding` to non-`nil`, evaluates `body` in implicit
`do`.
+## `loop`
+Function signature:
+
+```
+(loop binding-vec body*)
+```
+
+Recursive loop macro.
+
+Similar to `let`, but binds a special `recur` call that will reassign the values
+of the `binding-vec` and restart the loop `body*`.
+
+The first argument is a binding table with alternating symbols (or destructure
+forms), and the values to bind to them.
+
+For example:
+
+```fennel
+(loop [[first & rest] [1 2 3 4 5]
+ i 0]
+ (if (= nil first)
+ i
+ (recur rest (+ 1 i))))
+```
+
+This would destructure the first table argument, with the first value inside it
+being assigned to `first` and the remainder of the table being assigned to
+`rest`. `i` simply gets bound to 0.
+
+The body of the form executes for every item in the table, calling `recur` each
+time with the table lacking its head element (thus consuming one element per
+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