Guest User

Untitled

a guest
Apr 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. -module(channels_recorder).
  2.  
  3. -export([demo/0, surf/1]).
  4.  
  5. -record(channel, {station, show_title, genre, repeat}).
  6.  
  7. -define(CHANNELS, [
  8. #channel{station = "NBC",
  9. show_title = "Saturday Night Live",
  10. genre = "comedy",
  11. repeat = true},
  12. #channel{station = "FOX",
  13. show_title = "Cops",
  14. genre = "crime",
  15. repeat = true},
  16. #channel{station = "ESPN",
  17. show_title = "College Football",
  18. genre = "football",
  19. repeat = false},
  20. #channel{station = "HBO",
  21. show_title = "Curb Your Enthusiasm",
  22. genre = "Comedy",
  23. repeat = false}
  24. ]).
  25.  
  26.  
  27. demo() ->
  28. surf(?CHANNELS).
  29.  
  30.  
  31. surf(Channels) ->
  32. lists:foreach(fun process/1, Channels).
  33.  
  34. process(#channel{genre = "football"} = Channel) ->
  35. record(Channel);
  36.  
  37. process(#channel{genre = "comedy", repeat = false} = Channel) ->
  38. record(Channel);
  39.  
  40. process(#channel{genre = "crime", show_title = "Cops"}) ->
  41. skip;
  42.  
  43. process(#channel{genre = "crime"} = Channel) ->
  44. record(Channel);
  45.  
  46. process(_) ->
  47. skip.
  48.  
  49.  
  50. record(Channel) ->
  51. io:format("recording ~p.~n", [Channel#channel.show_title]).
Add Comment
Please, Sign In to add comment