User Tools

Site Tools


CSci 326 - Daily #5

Purpose: to gain experience with Elixir control structures (which are very different from Java, etc.) and applying Program Design requirements.

Part 1. Work through each example specified, creating a transcript file as in previous assignments.

  1. Work through the Pin Operator examples at These examples show how to do pattern matching on some variables in a collection but maintain the bindings of others, an important thing to know.
  2. Work through the Control Structures lesson at Only try those examples that use the iex> prompt.
  3. Write a function there in iex that uses the cond control structure to determine if a number x passed as parameter is divisible by 2, divisible by 3, or divisible by 5 in that order. Return a string of the form #{x} is divisible by 3! If not divisible by any of these, simply return not divisible. Test it with at least six values. It can be an anonymous function or you can define it in a module.

Part 2. Apply the Program Design requirements (including @spec, @doc, and @moduledoc) to the modules and functions you wrote in Dailies 2, 3, and 4. You can put these all in one file, called daily5.exs. Do not include any of your test code.

The elixir-lang guide on @spec includes a link to the complete list of typespecs one could use in a @spec.

Also, finish applying the Program Design requirements to the code examples done in class: sequential.exs

Email files to me AS AN ATTACHMENT.

cs326/daily5.txt · Last modified: 2021/09/13 14:54 by scarl