* `bytevector-length' doesn't accept a shared array from a bytevector
@ 2017-02-21 13:21 Diogo F. S. Ramos
2017-02-21 14:18 ` Daniel Llorens
0 siblings, 1 reply; 4+ messages in thread
From: Diogo F. S. Ramos @ 2017-02-21 13:21 UTC (permalink / raw)
To: guile-devel
I want to take the length of a shared array, but `bytevector-length'
throws an error claiming the shared array isn't a bytevector, even
though it prints the error argument as one.
--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use (rnrs bytevectors)
scheme@(guile-user)> (bytevector-length
(make-shared-array (make-bytevector 42)
list
7))
ERROR: In procedure bytevector-length:
ERROR: In procedure scm_c_bytevector_length: Wrong type argument in position 1 (expecting bytevector): #vu8(0 0 0 0 0 0 0)
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]>
--8<---------------cut here---------------end--------------->8---
I am using Guile 2.0.11, Debian Stable package 2.0.11+1-9.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: `bytevector-length' doesn't accept a shared array from a bytevector
2017-02-21 13:21 `bytevector-length' doesn't accept a shared array from a bytevector Diogo F. S. Ramos
@ 2017-02-21 14:18 ` Daniel Llorens
2017-02-21 18:51 ` Diogo F. S. Ramos
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Llorens @ 2017-02-21 14:18 UTC (permalink / raw)
To: Diogo F. S. Ramos; +Cc: guile-devel
On 21 Feb 2017, at 14:21, Diogo F. S. Ramos <dfsr@riseup.net> wrote:
> I want to take the length of a shared array, but `bytevector-length'
> throws an error claiming the shared array isn't a bytevector, even
> though it prints the error argument as one.
>
> --8<---------------cut here---------------start------------->8---
> scheme@(guile-user)> ,use (rnrs bytevectors)
> scheme@(guile-user)> (bytevector-length
> (make-shared-array (make-bytevector 42)
> list
> 7))
> ERROR: In procedure bytevector-length:
> ERROR: In procedure scm_c_bytevector_length: Wrong type argument in position 1 (expecting bytevector): #vu8(0 0 0 0 0 0 0)
>
> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]>
> --8<---------------cut here---------------end--------------->8---
>
> I am using Guile 2.0.11, Debian Stable package 2.0.11+1-9.
>
This is addressed in 2.1, by eb3d623da57e6d31a58d95f932345fb761f9b701. Your example will print #1vu8(0 0 ...) to signify that it's not a bytevector. You can use array-length here.
I suppose the patch could be applied to 2.0.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: `bytevector-length' doesn't accept a shared array from a bytevector
2017-02-21 14:18 ` Daniel Llorens
@ 2017-02-21 18:51 ` Diogo F. S. Ramos
2017-02-21 20:07 ` Daniel Llorens
0 siblings, 1 reply; 4+ messages in thread
From: Diogo F. S. Ramos @ 2017-02-21 18:51 UTC (permalink / raw)
To: Daniel Llorens; +Cc: guile-devel
> On 21 Feb 2017, at 14:21, Diogo F. S. Ramos <dfsr@riseup.net> wrote:
>
>> I want to take the length of a shared array, but `bytevector-length'
>> throws an error claiming the shared array isn't a bytevector, even
>> though it prints the error argument as one.
>>
>> I am using Guile 2.0.11, Debian Stable package 2.0.11+1-9.
>
> This is addressed in 2.1, by
> eb3d623da57e6d31a58d95f932345fb761f9b701. Your example will print
> #1vu8(0 0 ...) to signify that it's not a bytevector. You can use
> array-length here.
Thank you.
I didn't realize shared arrays are not bytevectors anymore and wrongly
assumed bytevector procedures could be applied to arrays, even tho array
procedures can be applied to bytevectors.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: `bytevector-length' doesn't accept a shared array from a bytevector
2017-02-21 18:51 ` Diogo F. S. Ramos
@ 2017-02-21 20:07 ` Daniel Llorens
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Llorens @ 2017-02-21 20:07 UTC (permalink / raw)
To: Diogo F. S. Ramos; +Cc: guile-devel
On 21 Feb 2017, at 19:51, Diogo F. S. Ramos <dfsr@riseup.net> wrote:
>> On 21 Feb 2017, at 14:21, Diogo F. S. Ramos <dfsr@riseup.net> wrote:
>>
>>> I want to take the length of a shared array, but `bytevector-length'
>>> throws an error claiming the shared array isn't a bytevector, even
>>> though it prints the error argument as one.
>>>
>>> I am using Guile 2.0.11, Debian Stable package 2.0.11+1-9.
>>
>> This is addressed in 2.1, by
>> eb3d623da57e6d31a58d95f932345fb761f9b701. Your example will print
>> #1vu8(0 0 ...) to signify that it's not a bytevector. You can use
>> array-length here.
>
> Thank you.
>
> I didn't realize shared arrays are not bytevectors anymore and wrongly
> assumed bytevector procedures could be applied to arrays, even tho array
> procedures can be applied to bytevectors.
AFAIR bytevector procedures have always failed with actual arrays.
However, the array procedures will return a root vector (a bytevector, an vector, etc.) whenever it's possible for them to do so. E.g. if you change 7 -> 42 in your example, make-shared-array will return a true bytevector. (make-typed-array 'vu8 VALUE LENGTH) will always return a bytevector. Yet another example, typing #1vu8(0 0 ...) in the terminal will print back #vu8(0 0 ...), and it is a true bytevector.
I wouldn't rely on this being true in the future, since I don't think it's documented.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-02-21 20:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-21 13:21 `bytevector-length' doesn't accept a shared array from a bytevector Diogo F. S. Ramos
2017-02-21 14:18 ` Daniel Llorens
2017-02-21 18:51 ` Diogo F. S. Ramos
2017-02-21 20:07 ` Daniel Llorens
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).