Hi All,
I'm sure I'm doing something stupid here, but I just can't get output vector ports to work. I've tried these two examples but get the same result :-
(*let* ((s (make-u8vector 3 0))) (with-output-to-u8vector s (*lambda* () (write-u8 65) (write-u8 45) (force-output))) s)
=> #u8(0 0 0)
(*let* ((s (make-u8vector 3 0))) (*let* ((p (open-u8vector s))) (write-u8 65 p) (write-u8 45 p) (close-output-port p) ) s)
=> #u8(0 0 0)
I can get input ports working fine i.e. I can read from a port from the vectors but the writes seem to completely fail to update the vector. Am I doing something wrong, or is there a bug in Gambit ? I'm using 4.4.2 on Windows.
Thanks
Andrew
Afficher les réponses par date
On Linux:
(with-output-to-u8vector (make-u8vector 0) (lambda () (write-u8 2)
(write-u8 5))) #u8(2 5)
On Windows:
(with-output-to-u8vector (make-u8vector 0) (lambda () (write-u8 2)
(write-u8 5 ))) #u8(2 5)
with-output-to-u8vector CREATES a new u8-vector, it is not destructive! so do like this:
(let ((s (make-u8vector 3 0)))
(set! s (with-output-to-u8vector s (lambda () (write-u8 65) (write-u8 45) (force-output)))) s) #u8(0 0 0 65 45)
Hi All,
I'm sure I'm doing something stupid here, but I just can't get output vector ports to work. I've tried these two examples but get the same result :-
(let ((s (make-u8vector 3 0))) (with-output-to-u8vector s (lambda () (write-u8 65) (write-u8 45) (force-output))) s)
=> #u8(0 0 0)
(*let* ((s (make-u8vector 3 0))) (*let* ((p (open-u8vector s))) (write-u8 65 p) (write-u8 45 p) (close-output-port p) ) s)
=> #u8(0 0 0)
I can get input ports working fine i.e. I can read from a port from the vectors but the writes seem to completely fail to update the vector. Am I doing something wrong, or is there a bug in Gambit ? I'm using 4.4.2 on Windows.
Thanks
Andrew
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On 31-Mar-09, at 3:46 PM, vasil wrote:
with-output-to-u8vector CREATES a new u8-vector, it is not destructive! so do like this:
(let ((s (make-u8vector 3 0)))
(set! s (with-output-to-u8vector s (lambda () (write-u8 65) (write-u8 45) (force-output)))) s) #u8(0 0 0 65 45)
Indeed a new vector will be created and the "initial vector" passed to with-output-to-u8vector is simply the prefix of the new vector.
You may wonder why this API was chosen. Well:
1) Internally a vector must be created and initialized, so it can save time to allow an initializing vector when the prefix is known.
2) This parameter can be used to specify other options, such as the character encoding. For example:
(map (lambda (x)
(cons x (with-output-to-u8vector (list char-encoding: x) (lambda () (write-char (integer->char 255)))))) '(ISO-8859-1 UTF-8 UTF-16BE UTF-16LE UTF-16 UTF UCS-2 UCS-4)) ((ISO-8859-1 . #u8(255)) (UTF-8 . #u8(195 191)) (UTF-16BE . #u8(0 255)) (UTF-16LE . #u8(255 0)) (UTF-16 . #u8(255 254 255 0)) (UTF . #u8(239 187 191 195 191)) (UCS-2 . #u8(255 254 255 0)) (UCS-4 . #u8(255 254 0 0 255 0 0 0)))
Marc