Lars Brinkhoff | 9 Aug 15:44 2006

Re: Collection utility

"Thomas F. Burdick" <tfb <at> OCF.Berkeley.EDU> writes:
> In 2001, I spent a little too much time thinking about the optimal
> interface to a collection utility, as evidenced by this thread on
> comp.lang.lisp:
> http://groups.google.com/groups?threadm=xcvsnbgix4v.fsf%40famine.OCF.Berkeley.EDU
>
> I'd thought I posted the collection utility I wrote as a result,
> but I can't find it anywhere.  So, three years later, here it is.

Two years later, triggered by rereading Thomas' post, and feeling a
need to implementing my own ideas about the optimal collection
utility, I came up with these two macros:

  "WITH-COLLECTOR (&KEY NAME TYPE &ALLOW-OTHER-KEYS) FORM* => RESULT

  NAME -- a symbol naming the collector; not evaluated.  The default is NIL.
  TYPE -- the type of the collection; evalutated.  The default is 'LIST.
  FORMS -- an implicit progn.
  RESULT -- the resulting collection.

  In the body, (COLLECT <object> :INTO <name>) is defined to collect
  an object into the corresponding named collection.  The default for
  NAME is NIL, which is also the default for INTO.  If NAME is not
  NIL, a variable by that name is bound to the result, and may be
  referenced anywhere within the body.  Additional keyword arguments
  are passed to the collector for type TYPE."

  "WITH-COLLECTORS ((NAME &KEY TYPE &ALLOW-OTHER-KEYS)*) FORM* => RESULT*

  NAME -- a symbol naming the collector; not evaluated.
(Continue reading)

Lars Brinkhoff | 11 Aug 10:08 2006

Re: Everything you didn't want to know about copying arrays

;;;; Slightly updated version.  Tested with SBCL, CLISP, ECL, and
;;;; Allegro CL, all of which have displayed interesting array quirks.

;;; Talking about array copying is a favourite pastime among Common
;;; Lispers, but what makes a successful copy?  Here's some code to
;;; quantitatively compare different array copying methods.
;;;
;;; The TEST function creates arrays with all possible combinations of
;;; (implementation-independent) properties.  For every array, a
;;; function is called to make a copy.  It then examines the copy and
;;; reports any differences compared to the original.
;;;
;;; Usage example:
;;; (test #'copy-array/row-major-aref-2)

(in-package :cl-user)

(defun safe-fill-pointer (array)
  (if (array-has-fill-pointer-p array)
      (fill-pointer array)))

(defun array-properties (array)
  (multiple-value-bind (dt dio) (array-displacement array)
    (list :simplep (typep array 'simple-array)
	  :dimensions (array-dimensions array)
	  :element-type (array-element-type array)
	  :contents array
	  :adjustable (adjustable-array-p array)
	  :has-fill-pointer-p (array-has-fill-pointer-p array)
	  :fill-pointer (safe-fill-pointer array)
(Continue reading)


Gmane