Advertisement
Guest User

Untitled

a guest
Jun 6th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.89 KB | None | 0 0
  1. #!/usr/bin/env escript
  2.  
  3. main(_) ->
  4.     List = [foo, bar, baz, ball, sack],
  5.     iterate(2, List).
  6.  
  7. iterate(Idx, List) ->
  8.         io:format("~p~n", [lists:nth(Idx, List)]),
  9.         case List == [] of
  10.         false ->
  11.                 iterate(Idx+1, List);
  12.         true ->
  13.                 io:format("Its over jim"),
  14.                 ok
  15.         end.
  16.  
  17. %% ^ this one "compiles" but doesnt match the true
  18.  
  19. ----
  20.  
  21. #!/usr/bin/env escript
  22.  
  23. main(_) ->
  24.     List = [foo, bar, baz, ball, sack],
  25.     iterate(2, List).
  26.  
  27. iterate(Idx, []) ->
  28.         io:format("Its over jim"),
  29.         ok;
  30. iterate(Idx, List) ->
  31.         io:format("~p~n", [lists:nth(Idx, List)]),
  32.         iterate(Idx+1, List).
  33.  
  34. %% ^ this one "compiles" but again never hits the empty list function.
  35.  
  36. same output for both
  37.  
  38. bar
  39. baz
  40. ball
  41. sack
  42. escript: exception error: no function clause matching lists:nth(1,[]) (lists.erl, line 169)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement