unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* make-shared-array and bitvectors
@ 2006-11-01 21:45 Ryan Moore
  2006-11-17 14:58 ` Neil Jerram
  0 siblings, 1 reply; 2+ messages in thread
From: Ryan Moore @ 2006-11-01 21:45 UTC (permalink / raw)


Making a shared array out of a bit vector does not result in a bit
vector being returned when the shared array does not have as many
elements as the original:

(define somebits (make-bitvector 8 #f))
(define subbits (make-shared-array somebits (lambda (dim) (list dim))
4))
(define allsubbits (make-shared-array somebits (lambda (dim) (list dim))
8))

(bitvector? somebits) => #t
(bitvector? subbits) => #f
(bitvector? allsubbits) => #t

(display somebits) =>#*00000000
(display subbits) => #b(#f #f #f #f)
(display allsubbits) => #*00000000

The 1.8 manual states: "Bit vectors are are also generalized vectors,
See Generalized Vectors, and can thus be used with the array procedures,
See Arrays" but as we can see, array procedures do not work as expected
on bitvectors.  If this is expected behavior, I feel it should be
clarified. I would think that making a shared array out of a bitvector
would result in a bitvector after all...


Thanks,
Ryan Moore



_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: make-shared-array and bitvectors
  2006-11-01 21:45 make-shared-array and bitvectors Ryan Moore
@ 2006-11-17 14:58 ` Neil Jerram
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Jerram @ 2006-11-17 14:58 UTC (permalink / raw)
  Cc: bug-guile

"Ryan Moore" <moorerw@westminster.edu> writes:

> Making a shared array out of a bit vector does not result in a bit
> vector being returned when the shared array does not have as many
> elements as the original:
>
> (define somebits (make-bitvector 8 #f))
> (define subbits (make-shared-array somebits (lambda (dim) (list dim))
> 4))
> (define allsubbits (make-shared-array somebits (lambda (dim) (list dim))
> 8))
>
> (bitvector? somebits) => #t
> (bitvector? subbits) => #f
> (bitvector? allsubbits) => #t

And in fact:

(eq? somebits allsubbits) => #t

Because of this special case code in scm_make_shared_array:

  if (1 == SCM_I_ARRAY_NDIM (ra) && 0 == SCM_I_ARRAY_BASE (ra))
    {
      SCM v = SCM_I_ARRAY_V (ra);
      size_t length = scm_c_generalized_vector_length (v);
      if (1 == s->inc && 0 == s->lbnd && length == 1 + s->ubnd)
	return v;
      ...
    }

So allsubbits is really just another reference to somebits, not a
shared array at all.

> The 1.8 manual states: "Bit vectors are are also generalized vectors,
> See Generalized Vectors, and can thus be used with the array procedures,
> See Arrays" but as we can see, array procedures do not work as expected
> on bitvectors.  If this is expected behavior, I feel it should be
> clarified. I would think that making a shared array out of a bitvector
> would result in a bitvector after all...

According to the current implementation, it's wrong (in general) to
expect (make-shared-array <bitvector> ...) to satisfy the bitvector?
predicate.

Is this a problem for you in practice?

Regards,
     Neil



_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-11-17 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-01 21:45 make-shared-array and bitvectors Ryan Moore
2006-11-17 14:58 ` Neil Jerram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).