[erlang-questions] idea: service pack one
Wed Nov 14 12:52:07 CET 2007
--- Vlad Dumitrescu <vladdu55@REDACTED> wrote:
> On Nov 14, 2007 9:26 AM, Thomas Lindgren
> <thomasl_erlang@REDACTED> wrote:
> > > a little off-topic: Maybe not _any_ regexp, but
> > > subset -- how would
> > > you handle 'a[b-y]+[0-9][^a-z]*u' in a
> > > straightforward way? It can't
> > > be transformed into a binary with many variables
> > > a lot of guards,
> > > it needs a state machine.
> > Either that or some compiler magic. An
> > implementation would be fairly straightforward if
> > had deep guards.
> Actually, if there's going to be some magic behind
> the scenes, why
> restrict this extended pattern matching to binaries?
Because implementing low-level regexps on strings is
fairly well-known. Just because it's magic doesn't
mean it includes a kitchen sink :-)
> I would very much
> like to be able to write something like for example
> [_*, term1, _+, term2+, _*] = L
> in order to find out if there is a term1 preceding a
> series of term2
> in the list, with at least one list element between
> them. In other
> words, full regexp matching on erlang terms instead
> of on characters.
Well, that sort of thing is a bit outside the original
question of conventional regexps on binaries/strings,
but I don't see why you couldn't provide the desired
functionality with a suitable parse transform (for
instance) and running the code inside a deep guard.
(Binary regexps could be done the same way.)
Note to those who wonder why I harp on about deep
guards: they are basically a convenience to avoid
messing around with generating nested case-expressions
and code duplication to express the same thing. As an
alternative, a 'cond'-expression might serve the same
purpose equally well. Cond is closer to reality than
deep guards but no, it's not there yet either :-)
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
More information about the erlang-questions