guile-user
[Top][All Lists]
Advanced

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

Re: uniform-array-read!


From: Ludovic Courtès
Subject: Re: uniform-array-read!
Date: Tue, 31 Jan 2006 18:26:54 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

William Xu <address@hidden> writes:

> Not in debian yet.. Guile 1.6.7 here.

Yeah, I know, unfortunately...

>>   guile> (define a (make-uniform-array #\nul 10))
>>   guile> (uniform-array-read! a (open-input-string (string #\001 #\002 
>> #\003)))
>>   3
>>   guile> a
>>   #s8(1 2 3 32 51 10 -102 96 48 10)
>>   guile>
>>
>> IOW, it seems to work fine --- except that:
>>
>>  1. The array is not properly initialized;
>
> It is.

Not with Guile 1.7, see above (it should only contain zeros starting
from the fourth element).

> What is that "result"?

See this comparison of Guile 1.6 and 1.7:

  $ guile-1.6
  guile> (make-uniform-array #\a 10)
  "aaaaaaaaaa"
  guile> (make-uniform-array #\nul 10)
  #y(0 0 0 0 0 0 0 0 0 0)
  guile> (make-uniform-array #\001 10)
  ""

  $ guile-1.7
  guile> (make-uniform-array #\a 10)
  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  guile> (make-uniform-array #\nul 10)
  #s8(15 -44 -17 16 16 4 118 8 0 0)
  guile> (make-uniform-array #\001 10)
  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

All the results differ.  Notably, Guile 1.7 fails to properly initialize
the arrays returned.

However, note that Guile 1.6 already handles the `#\nul' case specially:
in that case, `make-uniform-array' doesn't return a string (as explained
in the manual) but an array.

>    guile> (uniform-array-read! a (open-input-string (string #\001 #\002 
> #\003)))
>
> The second argument for uniform-array-read! is a string. In my codes, i
> tried to read binary data, precisely, a network packet. Does this
> matter? 

The second argument is an input port, not a string: `open-input-string'
returns an input port, like `open-input-file'.

Thanks,
Ludovic.




reply via email to

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