From nsiivola at common-lisp.net Wed Nov 2 16:38:46 2011 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Wed, 02 Nov 2011 09:38:46 -0700 Subject: [alexandria.git] updated branch master: c1644df beef up the README a bit Message-ID: The branch master has been updated: via c1644dfb6b0d8c74751ff080265e0e436e83c64b (commit) via 6fb9452b2bbd3867aa29bb0070d8919c4d1a572d (commit) from 268b6da4603d156cd22fedbfd5b8c5e67d2a394e (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 c1644dfb6b0d8c74751ff080265e0e436e83c64b Author: Nikodemus Siivola Date: Wed Nov 2 18:33:48 2011 +0200 beef up the README a bit commit 6fb9452b2bbd3867aa29bb0070d8919c4d1a572d Author: James M. Lawrence Date: Wed Nov 2 18:25:13 2011 +0200 fix bug in CURRY compiler-macro Multiple evaluation of the function argument, oops. ----------------------------------------------------------------------- Summary of changes: README | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- functions.lisp | 12 ++++++++---- tests.lisp | 22 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/README b/README index 930e7ec..8081c60 100644 --- a/README +++ b/README @@ -1,3 +1,52 @@ -Alexandria +Alexandria is a collection of portable public domain utilities that +meet the following constraints: -A collection of portable public domain utilities for Common Lisp. + * Utilities, not extensions: Alexandria will not contain conceptual + extensions to Common Lisp, instead limiting itself to tools and + utilities that fit well within the framework of standard ANSI + Common Lisp. Test-frameworks, system definitions, logging + facilities, serialization layers, etc. are all outside the scope of + Alexandria as a library, though well within the scope of Alexandria + as a project. + + * Conservative: Alexandria limits itself to what project members + consider conservative utilities. Alexandria does not and will not + include anaphoric constructs, loop-like binding macros, etc. + + * Portable: Alexandria limits itself to portable parts of Common + Lisp. Even apparently conservative and usefull functions remain + outside the scope of Alexandria if they cannot be implemented + portably. Portability is here defined as portable within a + conforming implementation: implementation bugs are not considered + portability issues. + +Homepage: + + http://common-lisp.net/project/alexandria/ + +Mailing lists: + + http://lists.common-lisp.net/mailman/listinfo/alexandria-devel + http://lists.common-lisp.net/mailman/listinfo/alexandria-cvs + +Repository: + + git://common-lisp.net/projects/alexandria/alexandria.git + +Documentation: + + http://common-lisp.net/project/alexandria/draft/alexandria.html + + (To build docs locally: cd doc && make html pdf info) + +Patches: + + Patches are always welcome! Please send them to the mailing list as + attachments, generated by "git format-patch -1". + + Patches should include a commit message that explains what's being + done and /why/, and when fixing a bug or adding a feature you should + also include a test-case. + + Be adviced though that right now new features are unlikely to be + accepted until 1.0 is officially out of the door. diff --git a/functions.lisp b/functions.lisp index 15032be..f703a99 100644 --- a/functions.lisp +++ b/functions.lisp @@ -1,6 +1,8 @@ (in-package :alexandria) -(declaim (inline ensure-function)) ; to propagate return type. +;;; To propagate return type and allow the compiler to eliminate the IF when +;;; it is known if the argument is function or not. +(declaim (inline ensure-function)) (declaim (ftype (function (t) (values function &optional)) ensure-function)) @@ -120,11 +122,13 @@ it is called with to FUNCTION." (multiple-value-call fn (values-list arguments) (values-list more))))) (define-compiler-macro curry (function &rest arguments) - (let ((curries (make-gensym-list (length arguments) "CURRY"))) - `(let ,(mapcar #'list curries arguments) + (let ((curries (make-gensym-list (length arguments) "CURRY")) + (fun (gensym "FUN"))) + `(let ((,fun (ensure-function ,function)) + ,@(mapcar #'list curries arguments)) (declare (optimize (speed 3) (safety 1) (debug 1))) (lambda (&rest more) - (apply ,function , at curries more))))) + (apply ,fun , at curries more))))) (defun rcurry (function &rest arguments) "Returns a function that applies the arguments it is called diff --git a/tests.lisp b/tests.lisp index a4a8e55..20caf8a 100644 --- a/tests.lisp +++ b/tests.lisp @@ -508,11 +508,33 @@ (funcall fun 2))) 4) +(deftest curry.4 + (let* ((x 1) + (curried (curry (progn + (incf x) + (lambda (y z) (* x y z))) + 3))) + (list (funcall curried 7) + (funcall curried 7) + x)) + (42 42 2)) + (deftest rcurry.1 (let ((r (rcurry '/ 2))) (funcall r 8)) 4) +(deftest rcurry.2 + (let* ((x 1) + (curried (rcurry (progn + (incf x) + (lambda (y z) (* x y z))) + 3))) + (list (funcall curried 7) + (funcall curried 7) + x)) + (42 42 2)) + (deftest named-lambda.1 (let ((fac (named-lambda fac (x) (if (> x 1) -- Alexandria hooks/post-receive From nsiivola at common-lisp.net Wed Nov 9 13:00:10 2011 From: nsiivola at common-lisp.net (Nikodemus Siivola) Date: Wed, 09 Nov 2011 05:00:10 -0800 Subject: [alexandria.git] updated branch master: 77b219a SHUFFLE on non-lists did not respect :START and :END Message-ID: The branch master has been updated: via 77b219a8361b9549aeb8941afc945fa2e3c84eb9 (commit) from c1644dfb6b0d8c74751ff080265e0e436e83c64b (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 77b219a8361b9549aeb8941afc945fa2e3c84eb9 Author: Jianshi Huang Date: Wed Nov 9 14:56:58 2011 +0200 SHUFFLE on non-lists did not respect :START and :END ----------------------------------------------------------------------- Summary of changes: sequences.lisp | 13 ++++++++----- tests.lisp | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/sequences.lisp b/sequences.lisp index f1e3f50..e7f1925 100644 --- a/sequences.lisp +++ b/sequences.lisp @@ -83,8 +83,9 @@ share structure with it." "Returns a random permutation of SEQUENCE bounded by START and END. Permuted sequence may share storage with the original one. Signals an error if SEQUENCE is not a proper sequence." - (declare (fixnum start) (type (or fixnum null) end)) - (typecase sequence + (declare (type fixnum start) + (type (or fixnum null) end)) + (etypecase sequence (list (let* ((end (or end (proper-list-length sequence))) (n (- end start))) @@ -94,12 +95,14 @@ error if SEQUENCE is not a proper sequence." (decf n)))) (vector (let ((end (or end (length sequence)))) - (loop for i from (- end 1) downto start - do (rotatef (aref sequence i) (aref sequence (random (+ i 1))))))) + (loop for i from start below end + do (rotatef (aref sequence i) + (aref sequence (+ i (random (- end i)))))))) (sequence (let ((end (or end (length sequence)))) (loop for i from (- end 1) downto start - do (rotatef (elt sequence i) (elt sequence (random (+ i 1)))))))) + do (rotatef (elt sequence i) + (elt sequence (+ i (random (- end i))))))))) sequence) (defun random-elt (sequence &key (start 0) end) diff --git a/tests.lisp b/tests.lisp index 20caf8a..babe0f4 100644 --- a/tests.lisp +++ b/tests.lisp @@ -1128,6 +1128,14 @@ s))) (nil t t)) +(deftest shuffle.3 + (let* ((orig (coerce (iota 21) 'vector)) + (copy (copy-seq orig))) + (shuffle copy :start 10 :end 15) + (list (every #'eql (subseq copy 0 10) (subseq orig 0 10)) + (every #'eql (subseq copy 15) (subseq orig 15)))) + (t t)) + (deftest random-elt.1 (let ((s1 #(1 2 3 4)) (s2 '(1 2 3 4))) -- Alexandria hooks/post-receive