User Tools

Site Tools


cs326:daily4

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 functions developed in this assignment, 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.Quadratic containing these functions:

  1. Develop a set of functions to determine if a quadratic equation has 2, 1, or 0 solutions.The equation has 0 solutions if it is degenerate that is, if the first coefficient is 0. The equation has 1 solution if the equation has repeated roots (when the discriminant is 0). The equation has 2 solutions otherwise, but notice that the solutions are complex if the discriminant is negative. Example functions:
    • degenerate - takes a number, the first coefficient
    • quad_solutions - takes a tuple containing three numbers, the coefficients
    • discriminant - this you already have

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

  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/daily4.txt · Last modified: 2021/09/12 14:02 by scarl