[erlang-questions] beginner: How should regexp:split/2 be replaced?
Robert Virding
robert.virding@REDACTED
Fri Apr 22 12:46:30 CEST 2011
In both cases there was no real room for discussion as the decision had already been made by the OTP group. As your quote shows. That the array module chose to index from 0 does not make the re/binary decisions more right. We are still stuck with two different indexing standards.
Robert
----- "Raimo Niskanen" <raimo+erlang-questions@REDACTED> wrote:
> On Tue, Apr 19, 2011 at 09:14:04PM +0000, Robert Virding wrote:
> > Perhaps its because they think that adding/subtracting one is too
> difficult. Or perhaps it is because they want to adhere to the
> convention that indexing starts at 0 in spite of that most other
> erlang things index from 1.
> >
> > Robert
> >
>
> It was zero-based in EEP 11
> http://www.erlang.org/eeps/eep-0011.html
> and there was no discussion about that EEP.
>
> This also surfaced in a diskussion about EEP 31:
> http://erlang.org/pipermail/eeps/2009-December/000278.html
>
> Patrik Nyblom wrote:
> >
> > Robert Virding wrote:
> > >
> > > - It seems like 'binary' indexes binaries from 0. Is this wise?
> While
> > > indexing them from 1 may not have been a good choice having two
> different
> > > standards must surely be much worse and be a source of future
> confusion. I
> > > know that 're' does this but I think that was a bad mistake!
> >
> > We (OTP), reluctantly, made the decision to have zero-based indices
> as a
> > rule for binary-oriented modules although Erlang is traditionally
> > one-based. The reason beeing foremost the hassle of
> > using one-based indices in bit syntax (the only thing you can make
> with a
> > one based index is to make it zero based, it's useless in bit-syntax
> until
> > that is done). Having different bases in different binary-oriented
> modules
> > would add to the confusion (and make for a less convenient
> interface).
> > So, the design relu is now that all indices in binaries are
> zero-based. I
> > obviously won't make this module an exception.
> >
> End of quote Patrik Nyblom.
>
> The array module is also zero based.
> http://www.erlang.org/doc/man/array.html
>
> / Raimo Niskanen
>
>
>
>
> > ----- "Ahmed Omar" <spawn.think@REDACTED> wrote:
> > > I mean i understand it's different indexing, but was there
> specific reason to change that?
> > >
> > >
> > > On Tue, Apr 19, 2011 at 4:18 PM, Ahmed Omar <
> spawn.think@REDACTED > wrote:
> > >
> >
> >
> >
> > regexp:split("Hello world, Hello", "[ ]*,[ ]*").
> > {ok,["Hello world","Hello"]}
> >
> > >
> > re:split("Hello world, Hello", "[ ]*,[ ]*",[{return, list}]).
> > ["Hello world","Hello"]
> >
> > >
> >
> > regexp:matches("Hello \n","\n").
> > {match,[{7,1}]}
> >
> > >
> > re:run("Hello \n","\n").
> > {match,[{6,1}]}
> >
> > >
> > but i'm not sure why the start position is different here
> >
> >
> > >
> > >
> > > On Tue, Apr 19, 2011 at 3:30 PM, Bengt Kleberg <
> bengt.kleberg@REDACTED > wrote:
> > >
> >
> > Greetings,
> > >
> > > I have inherited some code without a test directory. I get the
> following
> > > compiler warnings:
> > > ./compile_funcs.erl:603: Warning: regexp:split/2: the regexp
> module is
> > > deprecated (will be removed in R15A); use the re module instead
> > > ./compile_funcs.erl:645: Warning: regexp:matches/2: the regexp
> module is
> > > deprecated (will be removed in R15A); use the re module instead
> > >
> > > The lines are:
> > > {ok, Class} = regexp:split(Class0, "[ ]*,[ ]*"),
> > > and
> > > {match,A}=regexp:matches(String,"\n"),
> > >
> > > I thought "[ ]*,[ ]*" would mean:
> > > the character class of " " (space), 0 or many times, followed by
> literal
> > > "," followed by the character class of " " (space), 0 or many
> times.
> > >
> > > This is not the case and I am not having any luck with randomly
> > > constructing strings to find one that triggers a Class that is
> different
> > > from Class0.
> > >
> > > Perhaps someone knows what "[ ]*,[ ]*" really means, and what to
> replace
> > > these with when using the re module.
> > >
> > >
> > > bengt
> > >
> > > _______________________________________________
> > > erlang-questions mailing list
> > > erlang-questions@REDACTED
> > > http://erlang.org/mailman/listinfo/erlang-questions
> > >
> > >
> >
> > > --
> > > Best Regards,
> > > - Ahmed Omar
> > http://nl.linkedin.com/in/adiaa
> > Follow me on twitter
> > @spawn_think
> > >
> > >
> >
> > > --
> > > Best Regards,
> > > - Ahmed Omar
> > http://nl.linkedin.com/in/adiaa
> > Follow me on twitter
> > @spawn_think
> > >
> > > _______________________________________________ erlang-questions
> mailing list erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
>
>
> --
>
> / Raimo Niskanen, Erlang/OTP, Ericsson AB
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list