summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llama-test.el11
-rw-r--r--llama.el36
2 files changed, 19 insertions, 28 deletions
diff --git a/llama-test.el b/llama-test.el
index 3e380b8..e06719d 100644
--- a/llama-test.el
+++ b/llama-test.el
@@ -311,7 +311,6 @@
(cons 'list (nreverse body))))
(ert-deftest llama-test-502-vector nil
- :expected-result :failed
;; Real world example: (##-let [val %1] ...).
@@ -324,15 +323,11 @@
(llama-test--flatten [%2 [%1]]))))
(should (equal (##llama-test--flatten [%1 _%2 %3])
- ;; failure:
- ;; (lambda (%1 _%2 %3)
- ;; (llama-test--flatten [%1 llama--unused-argument %3]))
(lambda (%1 _%2 %3)
(llama-test--flatten [%1 %3]))))
)
(ert-deftest llama-test-502-dotted nil
- :expected-result :failed
;; Real world example: ???.
@@ -345,16 +340,10 @@
(llama-test--flatten (%1 %2 . %3)))))
(should (equal (##llama-test--flatten (%1 _%2 . %3))
- ;; failure:
- ;; (lambda (%1 _%2 %3)
- ;; (llama-test--flatten (%1 _%2 . %3)))
(lambda (%1 _%2 %3)
(llama-test--flatten (%1 . %3)))))
(should (equal (##llama-test--flatten (%1 _%2 %3 . %4))
- ;; failure:
- ;; (lambda (%1 _%2 %3 %4)
- ;; (llama-test--flatten (%1 _%2 %3 . %4)))
(lambda (%1 _%2 %3 %4)
(llama-test--flatten (%1 %3 . %4)))))
)
diff --git a/llama.el b/llama.el
index 591b283..0900a3f 100644
--- a/llama.el
+++ b/llama.el
@@ -198,24 +198,26 @@ this trickery, you can alternatively use this macro under the name
(expr)))))
((memq (car-safe expr) '(## quote))
expr)
- ((and (listp expr) (ignore-errors (length expr)))
- (let ((fnpos t))
- (mapcan (lambda (elt)
- (setq elt (llama--collect elt args fnpos))
- (setq fnpos nil)
- (and (not (eq elt llama--unused-argument))
- (list elt)))
- expr)))
- ((listp expr)
- (prog1 expr
- (while (consp (cdr expr))
- (llama--collect (car expr) args)
- (setq expr (cdr expr)))
+ ((or (listp expr)
+ (vectorp expr))
+ (let* ((vectorp (vectorp expr))
+ (expr (if vectorp (append expr ()) expr))
+ (fnpos (and (not vectorp)
+ (ignore-errors (length expr)))) ;proper-list-p
+ (ret ()))
+ (catch t
+ (while t
+ (let ((elt (llama--collect (car expr) args fnpos)))
+ (unless (eq elt llama--unused-argument)
+ (push elt ret)))
+ (setq fnpos nil)
+ (setq expr (cdr expr))
+ (unless (and expr (listp expr))
+ (throw t nil))))
+ (setq ret (nreverse ret))
(when expr
- (llama--collect (car expr) args)
- (llama--collect (cdr expr) args))))
- ((vectorp expr)
- (vconcat (mapcar (lambda (elt) (llama--collect elt args)) expr)))
+ (setcdr (last ret) (llama--collect expr args)))
+ (if vectorp (vconcat ret) ret)))
(expr)))
;;; Advices