[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue: SEQUENCE-FUNCTIONS-EXCLUDE-ARRAYS (Version 2)



Pitman: 
	"Actually, I bet some people don't ever used displaced-arrays because
	they seem like excess hair and/or because the side-effect consequences
	are hard to learn about. ... Displaced arrays may be taught in some
thorough
	courses and one or two advanced books, but I bet are largely
overlooked...
	Not to mention the fact that they inherently seem to violate an
	abstraction and some people might avoid them because of some feel that
	programs which use them are not clean."


I find a certain inconsistency in your argument that constructing
displaced-arrays is obtuse and unesthetic, while at the same time
stating that multi-dimensional arrays are naturally operated on as
vectors with elements laid out in row-major order. After all,
displaced-arrays are the only mechanism in common lisp that allows one
to adopt that view, and as such are indispensible. Indeed, one might
argue that for the inexperienced Lisp user, who has some knowledge of
"C" or "FORTRAN", displaced-arrays map directly into conventional use of
pointers into arrays.

On a more constructive note -- it seems like a small addition to the
array mechanism might address most of our concerns. Consider:

(defun flatten-array (array) 
	(cond ((vectorp array) array)
		((arrayp array) 
			(make-array (array-total-size array) 
				:element-type (array-element-type array)
				:displaced-to array))
		(t (error "Not an array: ~s" array))))

then "flatten-array" may be used in combination with sequence functions
to achieve the desired semantics, and would have the advantage of making
clear the intention of a code fragment. A primitive like "flatten-array"
is useful in other contexts as well, and would complement a
"row-major-aref" primitive.


							J.P.