APPROVE COMMIT
NOTE: This patch has been committed
# HG changeset patch
# User Aidan Kehoe <kehoea(a)parhasard.net>
# Date 1538128854 -3600
# Fri Sep 28 11:00:54 2018 +0100
# Node ID 45b565af61281f58888966bc576f3d0f5c0a50b0
# Parent 0f7b7204a7ff9acfa1ad4205b3d14c7ffff80375
Correct a couple of small bugs in #'byte-optimize-{cdr,car}; add tests
lisp/ChangeLog addition:
2018-09-28 Aidan Kehoe <kehoea(a)parhasard.net>
* byte-optimize.el (byte-optimize-car):
* byte-optimize.el (byte-optimize-cdr):
Leave erroring on zero arguments and returning nil on nil
arguments to #'byte-optimize-predicate within these functions.
tests/ChangeLog addition:
2018-09-28 Aidan Kehoe <kehoea(a)parhasard.net>
* automated/lisp-tests.el:
Supply tests on #'car, #'cdr, helping to flush out (especially)
byte-compiler problems down the line.
diff -r 0f7b7204a7ff -r 45b565af6128 lisp/ChangeLog
--- a/lisp/ChangeLog Mon Sep 17 22:59:05 2018 +0100
+++ b/lisp/ChangeLog Fri Sep 28 11:00:54 2018 +0100
@@ -1,3 +1,10 @@
+2018-09-28 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * byte-optimize.el (byte-optimize-car):
+ * byte-optimize.el (byte-optimize-cdr):
+ Leave erroring on zero arguments and returning nil on nil
+ arguments to #'byte-optimize-predicate within these functions.
+
2018-09-16 Aidan Kehoe <kehoea(a)parhasard.net>
* alist.el: Remove this.
diff -r 0f7b7204a7ff -r 45b565af6128 lisp/byte-optimize.el
--- a/lisp/byte-optimize.el Mon Sep 17 22:59:05 2018 +0100
+++ b/lisp/byte-optimize.el Fri Sep 28 11:00:54 2018 +0100
@@ -865,8 +865,7 @@
(defun byte-optimize-car (form)
(let ((arg (cadr form)))
(cond
- ((not arg)) ;; Return nil if called on nil
- ((and (byte-compile-constp arg)
+ ((and (byte-compile-constp arg) arg
(not (and (eq (car-safe arg) 'quote) (listp (cadr arg)))))
(byte-compile-warn "taking car of a non-list constant: %s" arg)
form)
@@ -881,8 +880,7 @@
(defun byte-optimize-cdr (form)
(let ((arg (cadr form)))
(cond
- ((not arg)) ;; Return nil if called on nil
- ((and (byte-compile-constp arg)
+ ((and (byte-compile-constp arg) arg
(not (and (consp arg) (eq (car arg) 'quote) (listp (cadr arg)))))
(byte-compile-warn "taking cdr of a non-list constant: %s" arg)
form)
diff -r 0f7b7204a7ff -r 45b565af6128 tests/ChangeLog
--- a/tests/ChangeLog Mon Sep 17 22:59:05 2018 +0100
+++ b/tests/ChangeLog Fri Sep 28 11:00:54 2018 +0100
@@ -1,3 +1,9 @@
+2018-09-28 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * automated/lisp-tests.el:
+ Supply tests on #'car, #'cdr, helping to flush out (especially)
+ byte-compiler problems down the line.
+
2018-08-22 Aidan Kehoe <kehoea(a)parhasard.net>
* automated/mule-tests.el:
diff -r 0f7b7204a7ff -r 45b565af6128 tests/automated/lisp-tests.el
--- a/tests/automated/lisp-tests.el Mon Sep 17 22:59:05 2018 +0100
+++ b/tests/automated/lisp-tests.el Fri Sep 28 11:00:54 2018 +0100
@@ -339,6 +339,44 @@
(Assert (eql (safe-length nil) 0))
;;-----------------------------------------------------
+;; Test `car' and `cdr'
+;;-----------------------------------------------------
+
+(Check-Error wrong-number-of-arguments (car))
+(Check-Error wrong-number-of-arguments (car '(1 2) 'foo))
+(Check-Error wrong-type-argument (car '[1 2]))
+(Assert (eq (car '(a . b)) 'a) "checking #'car on a constant dotted
pair")
+(Assert (eq (let ((pair '(b . a)))
+ (car pair))
+ 'b) "checking #'car on a bound dotted pair")
+(Assert (eql (car '(200 200 4 0 9)) 200)
+ "checking #'car on a constant list")
+(Assert (eql (let ((list (list 200 200 4 0 9))) (car list))
+ 200) "checking #'car on a bound list")
+(Assert (eql (car (list 200 200 4 0 9)) 200)
+ "checking #'car on a list constructed at runtime")
+
+(Check-Error wrong-number-of-arguments (cdr))
+(Check-Error wrong-number-of-arguments (cdr '(1 2) 'foo))
+(Check-Error wrong-type-argument (cdr '[1 2]))
+(Assert (eq (cdr '(a . b)) 'b) "checking #'cdr on a constant dotted
pair")
+(Assert (eq (let ((pair '(b . a)))
+ (cdr pair))
+ 'a) "checking #'cdr on a bound dotted pair")
+(Assert (equal (cdr '(200 200 4 0 9)) (list 200 4 0 9))
+ "checking #'cdr on a constant list")
+(Assert (equal (let ((list (list 200 200 4 0 9))) (cdr list))
+ '(200 4 0 9))
+ "checking #'cdr on a bound list")
+(Assert (equal (cdr (list 200 200 4 0 9))
+ '(200 4 0 9))
+ "checking #'cdr on a list constructed at runtime")
+(Assert (let* ((gensym (gensym))
+ (pair (cons 'a gensym)))
+ (eq (cdr pair) gensym))
+ "checking the result of #'cdr for #'eq-identity")
+
+;;-----------------------------------------------------
;; Arithmetic operations
;;-----------------------------------------------------
--
‘As I sat looking up at the Guinness ad, I could never figure out /
How your man stayed up on the surfboard after forty pints of stout’
(C. Moore)