Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env escript
- main(_) ->
- List = [foo, bar, baz, ball, sack],
- iterate(2, List).
- iterate(Idx, List) ->
- io:format("~p~n", [lists:nth(Idx, List)]),
- case List == [] of
- false ->
- iterate(Idx+1, List);
- true ->
- io:format("Its over jim"),
- ok
- end.
- %% ^ this one "compiles" but doesnt match the true
- ----
- #!/usr/bin/env escript
- main(_) ->
- List = [foo, bar, baz, ball, sack],
- iterate(2, List).
- iterate(Idx, []) ->
- io:format("Its over jim"),
- ok;
- iterate(Idx, List) ->
- io:format("~p~n", [lists:nth(Idx, List)]),
- iterate(Idx+1, List).
- %% ^ this one "compiles" but again never hits the empty list function.
- same output for both
- bar
- baz
- ball
- sack
- escript: exception error: no function clause matching lists:nth(1,[]) (lists.erl, line 169)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement