diff tests/automated/lisp-tests.el @ 5737:165315eae1ab

Make #'apply-partially more intelligent still when byte-compiled. lisp/ChangeLog addition: 2013-06-17 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el: * cl-macs.el (apply-partially): Be more intelligent about constructing (or not) compiled functions at runtime or compile time when making these closures. tests/ChangeLog addition: 2013-06-17 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Test #'apply-partially more extensively, given changes in cl-macs.el.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 17 Jun 2013 19:54:02 +0100
parents 3192994c49ca
children ffc0c5a66ab1
line wrap: on
line diff
--- a/tests/automated/lisp-tests.el	Mon Jun 17 10:23:00 2013 -0600
+++ b/tests/automated/lisp-tests.el	Mon Jun 17 19:54:02 2013 +0100
@@ -2950,12 +2950,34 @@
        (times-four (apply-partially '* four))
        (plus-twelve (apply-partially '+ 6 (* 3 2)))
        (construct-list (apply-partially 'list (incf four) (incf four)
-                                        (incf four))))
+                                        (incf four)))
+       (list-and-multiply
+        (apply-partially #'(lambda (a b c d &optional e)
+                             (cons (apply #'+ a b c d (if e (list e)))
+                                   (list* a b c d e)))
+                         ;; Constant arguments -> function can be
+                         ;; constructed at compile time
+                         1 2 3))
+       (list-and-four
+        (apply-partially #'(lambda (a b c d &optional e)
+                             (cons (apply #'+ a b c d (if e (list e)))
+                                   (list* a b c d e)))
+                         ;; Not constant arguments -> function constructed
+                         ;; at runtime.
+                         1 2 four)))
   (Assert (eql (funcall times-four 6) 24))
   (Assert (eql (funcall times-four 4 4) 64))
   (Assert (eql (funcall plus-twelve (funcall times-four 4) 4 4) 36))
   (Check-Error wrong-number-of-arguments (apply-partially))
-  (Assert (equal (funcall construct-list) '(5 6 7))))
+  (Assert (equal (funcall construct-list) '(5 6 7)))
+  (Assert (equal (funcall list-and-multiply 5 6) '(17 1 2 3 5 . 6)))
+  (Assert (equal (funcall list-and-multiply 7) '(13 1 2 3 7)))
+  (Check-Error wrong-number-of-arguments
+               (funcall list-and-multiply 7 8 9 10))
+  (Assert (equal (funcall list-and-four 5 6) '(21 1 2 7 5 . 6)))
+  (Assert (equal (funcall list-and-four 7) '(17 1 2 7 7)))
+  (Check-Error wrong-number-of-arguments
+               (funcall list-and-four 7 8 9 10)))
 
 ;; Test labels and inlining.
 (labels