aboutsummaryrefslogtreecommitdiffhomepage
path: root/anaphora.lisp
blob: 13bb980243d2257314d352e40d95a725a49f2e07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(in-package #:gtwiwtg.anaphora)

(defmacro afor (generator &body body)
  "Anaphoric FOR. Binds the values produced by GENERATOR to the variable IT.

Example: 

> (afor (times 3) (print it))
0
1
2

"
  `(for it ,expr ,@body))

(defmacro afold (init generator update)
  "Anaphoric FOLD. Binds the values produced by GENERATOR to IT, and
binds the accumulating variable to ACC.

Example:

> (afold 0 (times 10) (+ acc it))
45

"
  `(fold (acc ,init) (it ,expr) ,update))