Re: [racket-users] how to `read-char` from port using `latin-1` encoding?

2017-03-31 Thread Matthew Butterick
OK thanks. Both "latin1" and "iso-8859-1" do work with `reencode-input-port`.



> On Mar 31, 2017, at 1:08 PM, Jon Zeppieri  wrote:
> 
> Try using "iso-8859-1" as the name of the encoding, instead of "latin-1." -J
> 
> 
> On Fri, Mar 31, 2017 at 3:55 PM, Matthew Butterick  wrote:
>> IIUC when `read-char` reads from a port it assumes the port uses UTF-8
>> encoding. [1]
>> 
>> (My Racketuition suggests there might be a parameter called
>> `current-port-encoding` that controls what encoding is applied to the port,
>> but apparently not.)
>> 
>> So instead, one must convert the port explicitly. OK, this seems to work:
>> 
>> (open-input-string (bytes->string/latin-1 (port->bytes port)))
>> 
>> The problem is that I'm reading all the bytes first, which defeats the
>> port-ishness of the operation.
>> 
>> But if I try the promising-sounding `reencode-input-port`:
>> 
>> (reencode-input-port port "latin-1")
>> 
>> This doesn't work, because it relies on `bytes-open-converter`, which
>> apparently doesn't know about `latin-1` encoding (a teeny bit surprising
>> since other racket/base functions deal with this encoding)
>> 
>> Hence the question: is there a smarter way to read characters from a
>> `latin-1` encoded port?
>> 
>> 
>> [1] http://docs.racket-lang.org/reference/encodings.html?q=encoding
>> 
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] how to `read-char` from port using `latin-1` encoding?

2017-03-31 Thread Jon Zeppieri
Try using "iso-8859-1" as the name of the encoding, instead of "latin-1." -J


On Fri, Mar 31, 2017 at 3:55 PM, Matthew Butterick  wrote:
> IIUC when `read-char` reads from a port it assumes the port uses UTF-8
> encoding. [1]
>
> (My Racketuition suggests there might be a parameter called
> `current-port-encoding` that controls what encoding is applied to the port,
> but apparently not.)
>
> So instead, one must convert the port explicitly. OK, this seems to work:
>
> (open-input-string (bytes->string/latin-1 (port->bytes port)))
>
> The problem is that I'm reading all the bytes first, which defeats the
> port-ishness of the operation.
>
> But if I try the promising-sounding `reencode-input-port`:
>
> (reencode-input-port port "latin-1")
>
> This doesn't work, because it relies on `bytes-open-converter`, which
> apparently doesn't know about `latin-1` encoding (a teeny bit surprising
> since other racket/base functions deal with this encoding)
>
> Hence the question: is there a smarter way to read characters from a
> `latin-1` encoded port?
>
>
> [1] http://docs.racket-lang.org/reference/encodings.html?q=encoding
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] how to `read-char` from port using `latin-1` encoding?

2017-03-31 Thread Matthew Flatt
Try "latin1" (no hyphen).

I'm not sure of the standard for these names, but probably Racket's `latin-1` 
functions are misnamed.

> On Mar 31, 2017, at 3:55 PM, Matthew Butterick  wrote:
> 
> IIUC when `read-char` reads from a port it assumes the port uses UTF-8 
> encoding. [1] 
> 
> (My Racketuition suggests there might be a parameter called 
> `current-port-encoding` that controls what encoding is applied to the port, 
> but apparently not.)
> 
> So instead, one must convert the port explicitly. OK, this seems to work:
> 
> (open-input-string (bytes->string/latin-1 (port->bytes port)))
> 
> The problem is that I'm reading all the bytes first, which defeats the 
> port-ishness of the operation.
> 
> But if I try the promising-sounding `reencode-input-port`:
> 
> (reencode-input-port port "latin-1")
> 
> This doesn't work, because it relies on `bytes-open-converter`, which 
> apparently doesn't know about `latin-1` encoding (a teeny bit surprising 
> since other racket/base functions deal with this encoding)
> 
> Hence the question: is there a smarter way to read characters from a 
> `latin-1` encoded port?
> 
> 
> [1] http://docs.racket-lang.org/reference/encodings.html?q=encoding
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.