Homework 11 — Programming Language Paradigms

Objectives

Getting started with Erlang. Experimenting with using the Erlang shell and getting used to the Erlang syntax.

Due Date

Beginning of class session 27.

Tasks

  1. Use your SVN client to update your individual SVN repository. You should find a new folder, ErlangHomework. Within the folder is a file intro.erl. All your work for this assignment must be done in that file.
  2. Open intro.erl in your favorite text editor. Study the provided code. Be sure you read all of the comments provided.
  3. Launch the Erlang shell and compile the provided file. The following commands will be helpful:
  4. Become familiar with Erlang syntax by implementing and testing the functions listed below.

    I'm reassigning several of the same problems on this homework as on earlier ones. My intent is that you can focus on the differences between the languages in the context of problems that should be familiar. I hope you find this to be a good use of your time. If the problems seem too easy, please let me know.

    1. Implement and test a simple factorial function. See the comments in the file and the provided (but commented out) test code.
    2. Implement and test a simple Fibonacci function using multiple recursive calls. Call it slowFib(N).
    3. Implement and test an O(n) Fibonacci function. Do not Google for a solution. You would find one, but I won't believe that it's original. Call your solution fib(N).
    4. Implement and test a function first(N,L) that returns a list consisting of the first N elements of the list L.
    5. Implement and test a function haar(L) to calculate the 1-dimensional Haar wavelet on the list L. See homework 2 for a description of the Haar wavelet. WARNING: If you're pattern matching against an integer, make sure the argument is an integer, because 0 =/= 0.0. The trunc() function is your friend.

Turn-in Instructions

Turn-in your work by committing it to your SVN repository.