[racket] regexp-match-evt and file-position

From: Milo Arvidsson (miloarvidsson at hotmail.co.uk)
Date: Sat Jun 11 01:53:37 EDT 2011

In the following program, (sync (regexp-match-evt #rx"^..." in)) returns '(#"123") but (file-position in) returns 0 instead of 3:

#lang racket/base
(require racket/port)
(define-values (in out) (make-pipe))
(display "12345" out)
(sync (regexp-match-evt #rx"^..." in)) 
(file-position in)

That means there's a problem with regexp-match-evt, right? It means regexp-match-evt is not updating the input port's position following a successful match. 

If you append (read-char in) (file-position in) to this program, read-char will return #\4 and file-position will return 1. 

Anyway, regexp-match-evt introduces this problem when used with input ports returned by make-pipe, tcp-connect and tcp-accept, but it works fine with the input port returned by open-input-string. I looked at the definition of regexp-match-evt in collects/mzlib/ports.rkt but I can't identify the problem. (I'm using Racket v5.1.1 on Windows)

Posted on the users mailing list.