On this page:
Overview
Hoax+
List and vector primitves
Testing
Submitting
9.2

Assignment 5: List and vector primitives🔗

Due: Thursday, June 18, 11:59PM

Starter code: hoax-plus.zip

NOTE: You will need to update the a86 library by running raco pkg update a86 before completing this assignment.

The goal of this assignment is to gain proficiency with our representation of memory-allocated values by implementing a number of list and vector primitives.

Overview🔗

For this assignment, use the starter code in hoax-plus.zip, which is similar to the Hoax language we studied in class.

Hoax+🔗

The Hoax+ language extends the Hoax language we studied in class with four new unary primitives:

  • length: given a list, computes its length.

  • reverse: given a list, computes a list with elements in the reverse order of the given list.

  • list->vector: given a list, computes a vector with elements in the order of the given list.

  • vector->list: given a vector, computes a list with elements in the order of the given vector.

Unlike past assignments, you do not need to bring forward in any features from earlier assignments.

List and vector primitves🔗

The new primitives have been added to the parser and the interpreter. The behavior of compiled primitives should be consistent with the interpreter:

Examples

> (interp (parse '(length '())))

0

> (interp (parse '(length (cons 1 (cons 2 '())))))

2

> (interp (parse '(length #f)))

'err

> (interp (parse '(reverse '())))

'()

> (interp (parse '(reverse (cons 1 (cons 2 '())))))

'(2 1)

> (interp (parse '(reverse #f)))

'err

> (interp (parse '(list->vector '())))

'#()

> (interp (parse '(list->vector (cons 1 (cons 2 '())))))

'#(1 2)

> (interp (parse '(list->vector #f)))

'err

> (interp (parse '(vector->list (make-vector 0 #t))))

'()

> (interp (parse '(vector->list (make-vector 2 #t))))

'(#t #t)

> (interp (parse '(vector->list #f)))

'err

The interpreter is consistent with Racket’s own behavior, so if you’re unsure about what your compiler should do, you can look to Racket (or the interpreter) for guidance:

Examples

> (length '())

0

> (length (cons 1 (cons 2 '())))

2

> (length #f)

length: contract violation

  expected: list?

  given: #f

> (reverse '())

'()

> (reverse (cons 1 (cons 2 '())))

'(2 1)

> (reverse #f)

reverse: contract violation

  expected: list?

  given: #f

> (list->vector '())

'#()

> (list->vector (cons 1 (cons 2 '())))

'#(1 2)

> (list->vector #f)

list->vector: contract violation

  expected: list?

  given: #f

> (vector->list (make-vector 0 #t))

'()

> (vector->list (make-vector 2 #t))

'(#t #t)

> (vector->list #f)

vector->list: contract violation

  expected: vector?

  given: #f

Testing🔗

A small number of test cases have been provided in test/define-tests.rkt. There is function called test that contains I/O-free test cases and another called test/io that contains I/O tests. To run these tests, raco test test/run-interp-test.rkt will test the interpreter and raco test test/run-compile-tests.rkt will test the compiler. You are encouraged to add your own tests.

Submitting🔗

To submit, use make from within the hoax-plus directory to create a zip file containing your work and submit it to Gradescope.