control-flow.lisp - clic - Clic is an command line interactive client for gophe… | |
git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
LICENSE | |
--- | |
control-flow.lisp (1227B) | |
--- | |
1 (in-package :alexandria-2) | |
2 | |
3 (defun line-up-iter (thread-first-p acc forms) | |
4 "Iterative implementation for `thread-iter'. | |
5 | |
6 The THREAD-FIRST-P decides where to thread the FORMS, accumulating in AC… | |
7 (if forms | |
8 (line-up-iter thread-first-p | |
9 (let ((form (car forms))) | |
10 (if (listp form) | |
11 (if thread-first-p | |
12 (apply #'list (car form) acc (cdr form)) | |
13 (append form (cons acc nil))) | |
14 (list form acc))) | |
15 (cdr forms)) | |
16 acc)) | |
17 | |
18 (defmacro line-up-first (&rest forms) | |
19 "Lines up FORMS elements as the first argument of their successor. | |
20 Example: | |
21 | |
22 (thread-first | |
23 5 | |
24 (+ 20) | |
25 / | |
26 (+ 40)) | |
27 | |
28 is equivalent to: | |
29 | |
30 (+ (/ (+ 5 20)) 40) | |
31 | |
32 Note how the single '/ got converted into a list before | |
33 threading." | |
34 (line-up-iter t (car forms) (cdr forms))) | |
35 | |
36 (defmacro line-up-last (&rest forms) | |
37 "Lines up FORMS elements as the last argument of their successor. | |
38 Example: | |
39 | |
40 (thread-last | |
41 5 | |
42 (+ 20) | |
43 / | |
44 (+ 40)) | |
45 | |
46 is equivalent to: | |
47 | |
48 (+ 40 (/ (+ 20 5))) | |
49 | |
50 Note how the single '/ got converted into a list before | |
51 threading." | |
52 (line-up-iter nil (car forms) (cdr forms))) |