branch: elpa/llama
commit 763a6746e79ae773ae7951825b681fda42fb439c
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    No longer support shorthands in function position
---
 README.org    |  3 ++-
 llama-test.el | 23 +++++++++++++++++++++++
 llama.el      | 24 ++++++++++++++----------
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/README.org b/README.org
index 47478d72d5..2459950dc4 100644
--- a/README.org
+++ b/README.org
@@ -22,7 +22,8 @@ their names have to begin with ~&~.  Symbol ~&*~ specifies 
extra
 
 Instead of ~%1~, the shorthand ~%~ can be used; but that should
 only be done if it is the only argument, and using both ~%1~ and
-~%~ is not allowed.  Likewise ~&~ can be substituted for ~&1~.
+~%~ is not allowed.  Likewise ~&~ can be substituted for ~&1~.  Both
+shorthands cannot be used in function position.
 
 Instead of:
 
diff --git a/llama-test.el b/llama-test.el
index c313424a5f..8d1eeb48bb 100644
--- a/llama-test.el
+++ b/llama-test.el
@@ -277,6 +277,29 @@
                    (list  %2 %                 &4 &3))))
   )
 
+(ert-deftest llama-test-501-function-position nil
+
+  (should (equal (##+ (% %2 2) %1)
+                 (lambda (%1 %2)
+                   (+ (% %2 2) %1))))
+
+  (should (equal (##+ (* %2 2) %)
+                 (lambda (% %2)
+                   (+ (* %2 2) %))))
+
+  (should (equal (##% %2 2)
+                 (lambda (_%1 %2)
+                   (% %2 2))))
+
+  (should (equal (##* %1 2)
+                 (lambda (%1)
+                   (* %1 2))))
+
+  (should (equal (##% %2 %1)
+                 (lambda (%1 %2)
+                   (% %2 %1))))
+  )
+
 (ert-deftest llama-test-901-errors-first nil
   (should-error (##list  %1   &1))
   (should-error (##list  &1   %1))
diff --git a/llama.el b/llama.el
index a0b8489e6f..6c657ec47e 100644
--- a/llama.el
+++ b/llama.el
@@ -48,6 +48,7 @@
 ;; Instead of `%1', the shorthand `%' can be used; but that should
 ;; only be done if it is the only argument, and using both `%1' and
 ;; `%' is not allowed.  Likewise `&' can be substituted for `&1'.
+;; Both shorthands cannot be used in function position.
 
 ;; Instead of:
 ;;
@@ -137,7 +138,7 @@ this trickery, you can alternatively use this macro under 
the name
   (unless (symbolp fn)
     (signal 'wrong-type-argument (list 'symbolp fn)))
   (let* ((args (make-vector 10 nil))
-         (body (llama--collect body args))
+         (body (cdr (llama--collect (cons fn body) args)))
          (rest (aref args 0))
          (args (nreverse (cdr (append args nil))))
          (args (progn (while (and args (null (car args)))
@@ -175,7 +176,7 @@ this trickery, you can alternatively use this macro under 
the name
 
 (defconst llama--unused-argument (make-symbol "llama--unused-argument"))
 
-(defun llama--collect (expr args)
+(defun llama--collect (expr args &optional fnpos)
   (cond
    ((symbolp expr)
     (let ((name (symbol-name expr)))
@@ -187,9 +188,10 @@ this trickery, you can alternatively use this macro under 
the name
                             ((not pos) 1)
                             ((string-to-number pos))))
                  (sym (aref args pos)))
-            (when (and sym (not (equal expr sym)))
-              (error "`%s' and `%s' are mutually exclusive" expr sym))
-            (aset args pos expr))
+            (unless (and fnpos (memq expr '(% &)))
+              (when (and sym (not (equal expr sym)))
+                (error "`%s' and `%s' are mutually exclusive" expr sym))
+              (aset args pos expr)))
           (if (match-string 1 name)
               llama--unused-argument
             expr))
@@ -197,11 +199,13 @@ this trickery, you can alternatively use this macro under 
the name
    ((memq (car-safe expr) '(## quote))
     expr)
    ((and (listp expr) (ignore-errors (length expr)))
-    (mapcan (lambda (elt)
-              (setq elt (llama--collect elt args))
-              (and (not (eq elt llama--unused-argument))
-                   (list elt)))
-            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))

Reply via email to