[racket] Use regexps or something else?

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Jun 3 23:46:08 EDT 2011

15 minutes ago, Rodolfo Carvalho wrote:
> Hello,
> 
> Since I'm on regexps... next message!
> 
> I couldn't find a way to match groups.
> I'd like to have something like this:
> 
> (define t "
> 23                12
> 15                45
> 32                27")
> (regexp-match-groups* #px"(\\d+)\\s+(\\d+)" t)
> 
> => '(("23" "12") ("15" "45") ("32" "27"))
> 
> Does such a thing exist?

No.  You can do this:

  (regexp-match* #px"(\\d+)\\s+(\\d+)" t)

where regexp-match gives you all of the complete matches, but not the
matched groups.  It could be added, but it seems like a questionable
extension.


> I am trying to parse the output from a HPL benchmark result, which is
> composed by many blocks of the following:
> 
> T/V                N    NB     P     Q               Time
> Gflops
> --------------------------------------------------------------------------------
> WR00L2L4       29293   256     2     4             535.64
>  3.129e+01
> --------------------------------------------------------------------------------
> ||Ax-b||_oo/(eps*(||A||_oo*||x||_oo+||b||_oo)*N)=        0.0034782 ......
> PASSED
> ================================================================================
> 
> 
> Maybe there is a better way other than using regexps?

Why not read it line-by-line, then parse each line with a regexp?


> Actually it would be nice to have some kind of reader that know how to read
> and convert "3.129e+01" from scientific notation to regular number which I
> could operate with.

-> (read (open-input-string "3.129e+01"))
31.29

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.