Homework 13 — Programming Language Paradigms

Objectives

Getting started with Go. Experimenting with compiling Go programs getting used to the Go syntax.

Due Date

Beginning of class session 31.

Tasks

  1. Use your SVN client to update your individual SVN repository. You should find a new folder, GoHaar. Within the folder are three files: intro.go, intro_test.go, and Makefile.

    These files follow the conventions described in How to Write Go Code. While those conventions are primarily about writing new Go packages, we’re using them for the basic unit testing facilities they provide.

  2. Open intro_test.go in your favorite text editor. Study the provided code. Be sure you read the comments provided.
  3. cd into the GoHaar directory and execute the command gotest. The unit tests should execute but fail giving you something like this:

    [GoHaar]$ gotest
    rm -f _test/GoHaar.a _gotest_.6
    6g -o _gotest_.6 intro.go  intro_test.go
    rm -f _test/GoHaar.a
    gopack grc _test/GoHaar.a _gotest_.6 
    --- FAIL: GoHaar.TestFact
        fact(1) = -1, want 1.
        fact(3) = -1, want 6.
        fact(10) = -1, want 3628800.
    --- FAIL: GoHaar.TestFib
        fib(0) = -1, want 0.
        fib(1) = -1, want 1.
        fib(2) = -1, want 1.
        fib(3) = -1, want 2.
        fib(4) = -1, want 3.
        fib(5) = -1, want 5.
        fib(6) = -1, want 8.
        fib(10) = -1, want 55.
    --- FAIL: GoHaar.TestHaar
        haar([]float{0.000, 1.000})
              was []float{}
             want []float{0.500, -0.500}
        ...
    FAIL
    
  4. Become familiar with Go syntax by implementing and testing (using gotest) the functions listed below. All of your work must be done in the file intro.go.

    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 a simple factorial function. Call your solution fact(n)
    2. Implement an O(n) Fibonacci function. Call your solution fib(n).
    3. Implement a function haar(L) to calculate the 1-dimensional Haar wavelet on the slice of floats L. Careful! You’ll need to make fresh slices and will probably need to use copy to avoid mutating underlying arrays. See homework 2 for a description of the Haar wavelet.

Turn-in Instructions

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