[racket] line and column numbers lost after (relocate-input-port )

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Nov 30 22:41:25 EST 2013

It turns out that you have to enable line counting for the port passed
to `relocate-input-port`:

   (set! port (relocate-input-port
               (let ([p (reencode-input-port port "cp1251")])
                 (port-count-lines! p)
                 p)
               line col pos))

That fact is at least documented, although it wasn't obvious to me and
I had to read the documentation closely to notice the requirement.

At Wed, 27 Nov 2013 22:47:10 +0400, Dmitry Pavlov wrote:
> Hello,
> 
> Here is a piece of code that essentially shows my problem:
> 
> 
> #lang racket
> 
> (define port (open-input-file "anyfile.txt"))
> 
> (port-count-lines! port)
> 
> (let-values (((line col pos) (port-next-location port)))
>    (printf "before: ~a ~a ~a\n" line col pos)
>    (set! port (relocate-input-port
>                (reencode-input-port port "cp1251")
>                line col pos)))
> 
> ;; (port-count-lines! port) ;; does not change anything
> 
> (let-values (((line col pos) (port-next-location port)))
>    (printf "after: ~a ~a ~a\n" line col pos))
> 
> 
> Output:
> 
> before: 1 0 1
> after: #f #f 1
> 
> So the position is still there (good), but the
> line/column numbers are lost (bad). What did I miss?
> 
> 
> Best regards,
> 
> Dmitry
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.