[erlang-questions] newbie question

Erik Søe Sørensen eriksoe@REDACTED
Thu Nov 6 20:58:35 CET 2014


Hi there -

Apart from the atom-vs-Variable issue, I think you got your recursion wrong.

  [M1 | chunks(T1, P1)]

doesn't make too much sense (that I can see) - especially the "recurse with
P1 for Lst" part.

I think you mean either

  chunks(T1, [M1|Lst])

for a tail recursive loop, or

  chunks("") -> [];

  chunks(Str) -> ..., [M1 | chunks(T1)]

for "normal" recursion on the rest. At present, you code looks like a
confusion of the two (apart from the Lst/P1 difference).


Regards, and have fun on the learning curve,

Erik


Den 06/11/2014 20.27 skrev "Fred Youhanaie" <fly@REDACTED>:

>
> and of course the same goes for lst in chunks/2 :)
>
> On 06/11/14 19:09, James Aimonetti wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> str should be Str. Variables start with a capital letter.
>>
>> Le 2014-11-06 10:56, Charles Hixson a écrit :
>>
>>> Given the routine: -module(chunks). -export([chunks/1]).
>>> chunks(str)-> chunks(str, []).
>>>
>>> chunks("", lst)-> list:reverse(lst); chunks(str, lst)-> P1 =
>>> "^([[:alnum:]]+|[[:space:]]+|[[:punct:]]+|[[:cntrl:]]+|.)", [[],
>>> M1, T1] = re:split(str, P1, [{return, list}]), [M1 | chunks(T1,
>>> P1)].
>>>
>>> and the shell: 47> c(chunks). {ok,chunks}
>>>
>>> Why do I get: 49> chunks:chunks("Able was I ere I saw Elba."). **
>>> exception error: no function clause matching chunks:chunks("Able
>>> was I ere I saw Elba.") (chunks.erl, line 15) (Well, forget the
>>> like 15.  I took out a bunch of comments.)
>>>
>> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141106/1c0ed904/attachment.htm>


More information about the erlang-questions mailing list