git.fiddlerwoaroof.com
Browse code

Utilities and a macro to turn macros into lambdas

fiddlerwoaroof authored on 22/05/2016 08:10:37
Showing 2 changed files
... ...
@@ -2,6 +2,14 @@
2 2
 
3 3
 (in-package #:fwoar.lisputils)
4 4
 
5
+(defmacro neither (&rest forms) `(not (or ,@forms)))
6
+
7
+(defmacro neither-null (&rest forms)
8
+  `(neither ,@(loop for form
9
+                    in forms
10
+                    collecting `(null ,form))))
11
+
12
+
5 13
 (defmacro let-each ((&key (be '*)) &body forms)
6 14
   "Bind each element successively to the symbol specified via :be"
7 15
   `(let* ,(loop for form in forms
... ...
@@ -66,6 +74,15 @@
66 74
                         (go start))))))
67 75
         (helper (reverse list) body t))))
68 76
 
77
+(defmacro m-lambda (sym &rest args)
78
+  (let ((arglist (loop for x in args
79
+                       unless (member x (list '&optional '&key '&rest))
80
+                       collect (ctypecase x
81
+                                          (cons                  (car x))
82
+                                          ((or symbol keyword string) x)))))
83
+    `(lambda (,@args)
84
+       (,sym ,@arglist))))
85
+
69 86
 (defmacro destructuring-lambda ((&rest args) &body body)
70 87
   "A lambda whose arguments can be lambda-lists to be destructured"
71 88
   (let* ((args-syms (mapcar (alambda (gensym "arg"))
... ...
@@ -8,5 +8,6 @@
8 8
            #:copy-slots #:transform-alist #:%json-pair-transform
9 9
            #:%default-pair-transform #:default-when
10 10
            #:transform-result #:slots-to-pairs #:normalize-html
11
-           #:destructuring-lambda #:let-each #:let-first #:let-second))
11
+           #:destructuring-lambda #:let-each #:let-first #:let-second
12
+           #:neither #:neither-null #:m-lambda))
12 13