chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] array-lib : empty arrays advertise indices that they


From: Kon Lovett
Subject: Re: [Chicken-users] array-lib : empty arrays advertise indices that they cannot be indexed by
Date: Sat, 6 Oct 2007 19:44:53 -0700


On Oct 4, 2007, at 2:59 AM, Terrence Brannon wrote:

Re: http://www.call-with-current-continuation.org/eggs/array-lib.html

We read: (make-array [<prototype>]) will construct an empty array, not
a rank 0 array. Such arrays cannot be used with any setter or getter.
However, property queries will work, and they can be used as a
PROTOTYPE.

So I have several questions based on this information:

1 - what is meant by getter or setter? what particular functions? I'm
guessing array-ref might be one. And the one of most interest to me,
array-for-each-index

A getter is a field or element reference procedure. A setter is a field or element assignment procedure. Since the 'for-each' procedure is a "higher-order" operation it is not really a "getter" as it deals w/ the array in-aggregate. But, since it is implemented as a loop around a "getter" I did consider it, along w/ every other operation that accesses the elements of an array, as unusable w/ empty arrays.


2 - Since the docs make the distinction between an empty array and a
rank-0 array:
  a - how do these two things differ?
b - how can a rank-0 array be created since (make-array) does not do it?

Example: (array '#() 0 1)

And 'array-split' can create rank-0 arrays.


3 - It seems unusual to me that the array created by (make-array)
produces its indices, yet throws an error when you use the indices it
produces.

Actually it procedure no indices. The internals of the 'for-each' procedure is generating an index of 0, assuming the array is rank-0.

I'm trying to create some generic code which works for
arrays of any rank and it works fine for arrays of rank 1 and greater,
but for "rank-0" arrays, it is failing similar to below. Rank-0 is in
quotes because my empty arrays are not rank-0 per the docs. But I
would definitely like a rank-0 array, or at least something which does
not write it's own death sentence when queried for its indices :)

An empty array doesn't have indices to "query".

However, the 'for-each' procedure (and its' various siblings) should ignore an empty array. This is fixed in the 2.114 release.



(define e (make-array))
(define (a vec)
  (array-for-each-index
   (lambda (*indices*)
     (display *indices*)
     )
   vec
   ))

(define (b vec)
  (array-for-each-index
   (lambda (*indices*)
     (display (array-ref vec *indices*))
     )
   vec
   ))

(a e) ; displays 0
(b e) ; Error: (array-ref) out of range: (0)


_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users

Best Wishes,
Kon






reply via email to

[Prev in Thread] Current Thread [Next in Thread]