[erlang-questions] String Pattern Matching

Edwin Fine <>
Sun Sep 7 21:31:46 CEST 2008


>If you're really just dealing in words the penalty of a double
>reverse isn't as bad as the penalty of having to use REs.

True, but the penalty of writing and maintaining code that could be much
more clearly expressed as an RE may outweigh the performance penalty. If
there is not a large performance penalty I would go for the RE rather than
have to start writing code backwards ;-)

Regards,
Edwin Fine

On Sun, Sep 7, 2008 at 2:47 PM, Vance Shipley <> wrote:

> On Sun, Sep 07, 2008 at 10:02:37AM -0400, Luke Galea wrote:
> }  I get the sense that most erlangers feel that regular expressions
> }  aren't needed and that pattern matching can do the job.
>
> Whenever possible.
>
> }       ([m|l])ouse$ -> $1ice
>
> -module(inflector).
> -export([singularize/1]).
>
> singularize(Word) ->
>        L = lists:reverse(Word),
>        lists:reverse(singularize1(L)).
>
> singularize1("ecil" ++ L) ->
>        "esuol" ++ L;
> singularize1("ecim" ++ L) ->
>        "esuom" ++ L.
>
> 1> inflector:singularize("titmice").
> "titmouse"
>
> If you're really just dealing in words the penalty of a double
> reverse isn't as bad as the penalty of having to use REs.
>
>        -Vance
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080907/ab19ab0b/attachment.html>


More information about the erlang-questions mailing list