Simplify generated rules code.
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 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/can.lisp b/can.lisp
index 9e66aa8..51bba17 100644
--- a/can.lisp
+++ b/can.lisp
@@ -47,15 +47,27 @@
(flet ((unify (r x wild)
(if (facts:binding-p r)
(push (cons r x) bindings)
- (push `(or (eq ,r ,wild)
- (lessp:lessp-equal ,r ,x))
- constants))))
+ (if (keywordp r)
+ (unless (eq r wild)
+ (push `(lessp:lessp-equal ,r ,x)
+ constants))
+ (push `(or (eq ,r ,wild)
+ (lessp:lessp-equal ,r ,x))
+ constants))))
+ (join (prefix list)
+ (when list
+ (if (cdr list)
+ `((,prefix ,@list))
+ list))))
(unify o object :all)
(unify a action :admin)
- (unify s subject :everyone))
- `(when (and ,@constants
- ,@(sublis bindings specs))
- ,p))))
+ (unify s subject :everyone)
+ (car
+ (join 'when
+ `(,@(join 'and
+ `(,@constants ,@(join 'progn
+ (sublis bindings specs))))
+ ,p)))))))
#+nil
(can/rule 'user ':edit 'object (second *rules*))