[erlang-questions] concentate solution well ??

Bob Ippolito bob@REDACTED
Sun Feb 1 19:37:57 CET 2015


You should be able to make that assessment yourself. Does this program
compile? Does it work for the example? Does it work for other examples you
can come up with?

On Sun, Feb 1, 2015 at 9:27 AM, Roelof Wobben <r.wobben@REDACTED> wrote:

>  Roelof Wobben schreef op 1-2-2015 om 12:08:
>
> Bob Ippolito schreef op 1-2-2015 om 11:24:
>
> The goal is to solve the problem as stated such that it would work for
> *any* example, not just that one. It's very easy to come up with an example
> that does not work with your implementation.
>
>  Perhaps you should read the source for the lists module, and take the
> time to try and understand it.
> https://github.com/erlang/otp/blob/maint/lib/stdlib/src/lists.erl
>
> On Sun, Feb 1, 2015 at 2:14 AM, Roelof Wobben <r.wobben@REDACTED> wrote:
>
>> Hello,
>>
>> I have this exercise of the Erlang programming book.
>>
>> Write a function that, given a list of lists, will concatenate them.
>> Example:
>> concatenate([[1,2,3], [], [4, five]]) ⇒ [1,2,3,4,five].
>> Hint: you will have to use a helpfunction and concatenate the lists in
>> several steps.
>>
>> But I do not need to use a helper function because it can be solved like
>> this :
>>
>> concatenate( [List1 , List2 , List3] ) ->
>>     List1 ++ List2 ++ List3.
>>
>> Or is this not the solution that is meant on this exercise ?
>> Do I need to solve it by using pattern matching ?
>>
>> Roelof
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
>
> Thanks, I will do this,
>
> But there is one problem.
>
> The source is full of -spec and in programming erlang that is explained in
> chapter 18 where Im trying exercises of chapter 3.
>
> Roelof
>
>
>
> _______________________________________________
> erlang-questions mailing listerlang-questions@REDACTED://erlang.org/mailman/listinfo/erlang-questions
>
>
>
> This solution better ?
>
> concatenate([]) ->
>     [].
>
> concatenate([List] ) ->
>     concatenate2(List1, []).
>
> concatenate2([], List) ->
>     List;
>
> concatenate2([Head| Tail], List) ->
>     concatenate2(Tail, [Head | List])
>
> Roelof
>
>
> _______________________________________________
> 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/20150201/5926d298/attachment.htm>


More information about the erlang-questions mailing list