That is an interesting and probably much better way to do it.
Of course I did remember -0/42 … *clears throat* (not) :D

Thank you!

On Monday, April 23, 2018 at 12:03:38 AM UTC+2, Matthew Butterick wrote:
> On Apr 22, 2018, at 1:40 PM, Zelphir Kaltstahl < 
> <javascript:>> wrote:
> Ah OK, I understand that additional newline. Since the code matching the
> regex is run before that newline gets in, the newline will be on the
> input port.
> In DrRacket I observe the following:
> (I remembered that there are negative numbers :D and my regex got a bit
> more complicated.)
> Parsing numbers with regex is prone to error, because you'll often miss 
> edge cases. For instance, did you remember that -0/42 is an exact integer?
> A nice way to avoid these headaches is to delegate the heavy lifting to 
> `read`, and then just test the result value:
> #lang racket
> (for/first ([val (in-port read)]
>             #:when (exact-integer? val))
>            val) 

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 
For more options, visit

Reply via email to