From nsiivola at common-lisp.net Sat Oct 29 21:35:42 2011 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Sat, 29 Oct 2011 14:35:42 -0700 Subject: [alexandria.git] updated branch master: cd15854 fix edge-case in CIRCULAR-TREE-P Message-ID: The branch master has been updated: via cd158549ef56f10ef660f22cf4f9ddd96f0693c3 (commit) from 3eacfac87b27654f7ca9eeaf1ce40344b8136b03 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit cd158549ef56f10ef660f22cf4f9ddd96f0693c3 Author: Anton Kovalenko Date: Sun Oct 30 00:33:42 2011 +0300 fix edge-case in CIRCULAR-TREE-P CIRCULAR-TREE-P had an unfortunate corner case, causing it to overflow the stack (seen and repoted at #lisp for '#1=(#1#).) The problem is caused by the end-test (of the outer DO) being run before the body has a first chance to check for (member slow seen). ----------------------------------------------------------------------- Summary of changes: lists.lisp | 16 +++++++++------- tests.lisp | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lists.lisp b/lists.lisp index ffe418a..6367bc7 100644 --- a/lists.lisp +++ b/lists.lisp @@ -151,14 +151,16 @@ destructively modifying it and saves back the result into the place.") (and (consp object) (do ((fast (cons (car object) (cdr object)) (cddr fast)) (slow object (cdr slow))) - ((or (not (consp fast)) (not (consp (cdr slow)))) - (do ((tail object (cdr tail))) - ((not (consp tail)) - nil) - (let ((elt (car tail))) - (circularp elt (cons object seen))))) + (nil) (when (or (eq fast slow) (member slow seen)) - (return-from circular-tree-p t)))))) + (return-from circular-tree-p t)) + (when (or (not (consp fast)) (not (consp (cdr slow)))) + (return + (do ((tail object (cdr tail))) + ((not (consp tail)) + nil) + (let ((elt (car tail))) + (circularp elt (cons object seen)))))))))) (circularp object nil))) (defun proper-list-p (object) diff --git a/tests.lisp b/tests.lisp index b9e2277..ef7d19d 100644 --- a/tests.lisp +++ b/tests.lisp @@ -606,6 +606,10 @@ (circular-tree-p quite-dotted))) (t t t t t t nil nil)) +(deftest circular-tree-p.2 + (alexandria:circular-tree-p '#1=(#1#)) + t) + (deftest proper-list-p.1 (let ((l1 (list 1)) (l2 (list 1 2)) -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Sat Oct 29 21:45:45 2011 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Sat, 29 Oct 2011 14:45:45 -0700 Subject: [alexandria.git] updated branch master: 75f9136 improved COPY-ARRAY Message-ID: The branch master has been updated: via 75f9136a7c62d2da139e2f45b9dad5b8aa021fa2 (commit) from cd158549ef56f10ef660f22cf4f9ddd96f0693c3 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 75f9136a7c62d2da139e2f45b9dad5b8aa021fa2 Author: Svante Carl v. Erichsen Date: Sun Oct 30 00:42:02 2011 +0300 improved COPY-ARRAY No need to depend on the vagaries of ADJUST-ARRAY. ----------------------------------------------------------------------- Summary of changes: arrays.lisp | 30 ++++++++++++++---------------- tests.lisp | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/arrays.lisp b/arrays.lisp index 670880f..76c1879 100644 --- a/arrays.lisp +++ b/arrays.lisp @@ -1,20 +1,18 @@ (in-package :alexandria) -(defun copy-array (array &key - (element-type (array-element-type array)) - (fill-pointer (and (array-has-fill-pointer-p array) - (fill-pointer array))) - (adjustable (adjustable-array-p array))) +(defun copy-array (array &key (element-type (array-element-type array)) + (fill-pointer (and (array-has-fill-pointer-p array) + (fill-pointer array))) + (adjustable (adjustable-array-p array))) "Returns an undisplaced copy of ARRAY, with same fill-pointer and adjustability (if any) as the original, unless overridden by the keyword -arguments. Performance depends on efficiency of general ADJUST-ARRAY in the -host lisp -- for most cases a special purpose copying function is likely to -perform better." - (let ((dims (array-dimensions array))) - ;; Dictionary entry for ADJUST-ARRAY requires adjusting a - ;; displaced array to a non-displaced one to make a copy. - (adjust-array - (make-array dims - :element-type element-type :fill-pointer fill-pointer - :adjustable adjustable :displaced-to array) - dims))) +arguments." + (let* ((dimensions (array-dimensions array)) + (new-array (make-array dimensions + :element-type element-type + :adjustable adjustable + :fill-pointer fill-pointer))) + (dotimes (i (array-total-size array)) + (setf (row-major-aref new-array i) + (row-major-aref array i))) + new-array)) diff --git a/tests.lisp b/tests.lisp index ef7d19d..cb1978c 100644 --- a/tests.lisp +++ b/tests.lisp @@ -29,6 +29,24 @@ (eql (fill-pointer orig) (fill-pointer copy))))) nil t t t) +(deftest copy-array.3 + (let* ((orig (vector 1 2 3)) + (copy (copy-array orig))) + (typep copy 'simple-array)) + t) + +(deftest copy-array.4 + (let ((orig (make-array 21 + :adjustable t + :fill-pointer 0))) + (dotimes (n 42) + (vector-push-extend n orig)) + (let ((copy (copy-array orig + :adjustable nil + :fill-pointer nil))) + (typep copy 'simple-array))) + t) + (deftest array-index.1 (typep 0 'array-index) t) -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Sat Oct 29 21:53:02 2011 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Sat, 29 Oct 2011 14:53:02 -0700 Subject: [alexandria.git] updated branch master: 0e6be92 improved -- well, fixed -- SUBFACTORIAL Message-ID: The branch master has been updated: via 0e6be9262e000c8748942379d9c18778b393dd99 (commit) from 75f9136a7c62d2da139e2f45b9dad5b8aa021fa2 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0e6be9262e000c8748942379d9c18778b393dd99 Author: Mason Smith Date: Sun Oct 30 00:49:29 2011 +0300 improved -- well, fixed -- SUBFACTORIAL Plus tests. ----------------------------------------------------------------------- Summary of changes: numbers.lisp | 11 ++++++----- tests.lisp | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/numbers.lisp b/numbers.lisp index 0fa29a4..03430cc 100644 --- a/numbers.lisp +++ b/numbers.lisp @@ -227,11 +227,12 @@ greater then K." (defun subfactorial (n) "Subfactorial of the non-negative integer N." (check-type n (integer 0)) - (case n - (0 1) - (1 0) - (otherwise - (floor (/ (+ 1 (factorial n)) (exp 1)))))) + (if (zerop n) + 1 + (do ((x 1 (1+ x)) + (a 0 (* x (+ a b))) + (b 1 a)) + ((= n x) a)))) (defun count-permutations (n &optional (k n)) "Number of K element permutations for a sequence of N objects. diff --git a/tests.lisp b/tests.lisp index cb1978c..a4a8e55 100644 --- a/tests.lisp +++ b/tests.lisp @@ -991,6 +991,31 @@ (list p xv)) (2 #(10 2 10))) +(deftest subfactorial.1 + (mapcar #'subfactorial (iota 22)) + (1 + 0 + 1 + 2 + 9 + 44 + 265 + 1854 + 14833 + 133496 + 1334961 + 14684570 + 176214841 + 2290792932 + 32071101049 + 481066515734 + 7697064251745 + 130850092279664 + 2355301661033953 + 44750731559645106 + 895014631192902121 + 18795307255050944540)) + ;;;; Arrays #+nil -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Sat Oct 29 22:08:59 2011 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Sat, 29 Oct 2011 15:08:59 -0700 Subject: [alexandria.git] updated branch master: 268b6da declare LAST ignorable in PROPER-LIST-LENGTH and friends Message-ID: The branch master has been updated: via 268b6da4603d156cd22fedbfd5b8c5e67d2a394e (commit) from 0e6be9262e000c8748942379d9c18778b393dd99 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 268b6da4603d156cd22fedbfd5b8c5e67d2a394e Author: Antony Date: Sun Oct 30 01:06:25 2011 +0300 declare LAST ignorable in PROPER-LIST-LENGTH and friends Clozure CL at least considers it currently unused and signals a style warning. ----------------------------------------------------------------------- Summary of changes: lists.lisp | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lists.lisp b/lists.lisp index 6367bc7..00b42fa 100644 --- a/lists.lisp +++ b/lists.lisp @@ -198,7 +198,8 @@ designator of the expected type in a TYPE-ERROR." (slow (cons (car list) (cdr list)) (cdr slow)) ,@(when step (list step))) (nil) - (declare (dynamic-extent slow) ,@(when declare (list declare))) + (declare (dynamic-extent slow) ,@(when declare (list declare)) + (ignorable last)) (when (safe-endp fast) (return ,ret1)) (when (safe-endp (cdr fast)) @@ -211,10 +212,10 @@ designator of the expected type in a TYPE-ERROR." ;; KLUDGE: Most implementations don't actually support lists with bignum ;; elements -- and this is WAY faster on most implementations then declaring ;; N to be an UNSIGNED-BYTE. - (fixnum n) + (fixnum n) (1- n) n) - + (def lastcar (list) "Returns the last element of LIST. Signals a type-error if LIST is not a proper list." @@ -222,7 +223,7 @@ proper list." nil (cadr last) (car fast)) - + (def (setf lastcar) (object list) "Sets the last element of LIST. Signals a type-error if LIST is not a proper list." -- Alexandria hooks/post-receive