[racket] Use regexps or something else?

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Sat Jun 4 00:02:42 EDT 2011

On Sat, Jun 4, 2011 at 00:46, Eli Barzilay <eli at barzilay.org> wrote:

> 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.
>
>



So then how useful are groups? Only to re-match them?
Like "(quack)\\1"...






>
> > 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?
>


I wouldn't be a bad idea. I can filter-out non-matching lines and split the
rest... oh yes, since I have things split by spaces I can use regexp-split
 :)




>
> > 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
>
>
And is there a way to integrate that with reading the output from the
regexp?
Something like a "scanf"?

Ok, don't tell me, I will figure out in the next minutes :D

[]'s

Rodolfo Carvalho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110604/42d0fcf6/attachment.html>

Posted on the users mailing list.