[racket] Use regexps or something else?

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Jun 4 00:16:52 EDT 2011

7 minutes ago, Rodolfo Carvalho wrote:
> On Sat, Jun 4, 2011 at 00:46, Eli Barzilay <eli at barzilay.org> wrote:
> > 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"...

No, you get the groups results when you do a simple `regexp-match'.
It just happens that `regexp-match*' was made to return the complete
matches, it could have returned the subgroups too.  Like I said, it
could be added -- but every use that I've seen was one that got more
benefit from restructuring the code differently.  (As is in your
case.)


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

Actually, I should have used the easier answer:

  (string->number "3.129e+01")


> And is there a way to integrate that with reading the output from
> the regexp?  Something like a "scanf"?

I'm not sure that I'm following that, but you could just do something
like this:

  -> (map string->number (regexp-match* #rx"[^ ]+" "1.23 4e2"))
  '(1.23 400.0)

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


Posted on the users mailing list.