[erlang-questions] List Split into [H|T] is not working

Harit Himanshu harit.subscriptions@REDACTED
Sun Feb 22 00:21:32 CET 2015


Hey there,

I am pretty sure I am messing up, but can't figure out really.

Here is what I do

-module(solution).

-export([main/0]).

main() ->
  Input = read_input([]),
  [S | X] = Input,
  io:format("S=~p, X=~p~n", [S, X]),
  repeat(S, X).

read_input(Input) ->
  case io:fread("", "~d") of
    {ok, [N]} -> read_input([N | Input]);
    _ -> [lists:reverse(Input)]
  end.


and when I run it, I get

5> c(solution).

solution.erl:20: Warning: function string_to_integer_list/1 is unused

{ok,solution}

6> solution:main().

2

3

4

5

.

S=[2,3,4,5], X=[]

ok

7>


What's wrong here?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150221/19ce81da/attachment.htm>


More information about the erlang-questions mailing list