| Here is an example of an array library implemented entirely in arc . The arrays are not built-in data types, such as common Common Lisp (and Scheme) arrays, but rather settable, stateful functions, that take integer arguments. For example arc> (= v (array 4 '(a b c d)))
#<procedure>
makes a vector, arc> (v 1)
b
gets an element, and arc> (array>list v)
(array (4) (a b c d))
spits out the whole content. The rank of the array is in (v 'rank) while (v 'dim) gives dimension. Calling the array with no arguments gives basic info. Elements are set with the <- macro: arc> (<- (v 0) 0)
0
arc> (array>list v)
(array (4) (0 b c d))
The <- is basically a wrapper for (v 'setter).As an example of usage, take matrix inversion arc> (array>list (inv (array '(2 2) '((1 -1) (-1 4)))))
(array (2 2) ((4/3 1/3) (1/3 1/3)))
The array implementation is at
"http://folk.uio.no/jornv/arc/array.arc"Basically I think using functions as arrays are a good thing since there are no accessors (a pain in the ...), and you do not need to know what's under the hood - it can be hash tables, row major arrays or column major arrays, all appearing similar. |