User Tools

Site Tools


cs326:listomaps

CSci 326: Daily 4

Reading: Who uses Erlang/Elixir and why?.

Part 1. For two of the companies listed in the reading, explain the most important reason they choose to use BEAM languages. Support your reason with details from the article.

For the next part, try pattern matching on the parameters where it makes sense. Write alpha tests directly into your script (call it daily4.exs).

Part 2. Define a module Daily4.Playlist (this can go in the same file) containing these functions:

HEY!!! THIS IS DUMB. READ IT CAREFULLY AND FIND A WAY TO MAKE THIS LESS STUPID!!! For example, look at how we use it in HW 1 and HW 2

  1. You can combine the built-in data structures as in, for example, a list of maps:
    [%{:artist => "howling wolf"}, %{:artist => "three dog night"}]

    Write a function that takes a list of maps and a single map, and returns a new list with the single map added to the end.

  2. In your script file, create a list containing at least 5 songs; call it playlist. Each song is a map as in the previous question but with three keys :artist, :title, and :duration. In this list, have at least 2 songs by the same artist. Test your function with this list and several others of your own devising.
    Note: You can put any expression that can be converted to a string inside the #{…} used inside the string we send to IO.puts (or any string anywhere). This is called string interpolation. Example:
    lst = ["one", 2 , "three"]
    
    IO.puts "Here's the first entry: #{hd lst}"


    Note on testing: it is important to test edge cases. For lists, that includes the empty list, a singleton list, and a list with several items. So along with playlist described above, include at least 3 more tests.

We'll be building more interesting examples with this notion of a playlist in future assignments.

cs326/listomaps.txt · Last modified: 2021/09/22 13:11 by scarl