Lab 12

Lab 12 Instructions #

Reminders #

  • While students are coming into class, feel free to go ahead and download the lab materials in preparation for the start of the lab proper.

  • Ask for help from the staff (http://mydigitalhand.org). That’s what we’re here for. Even if you think you’ve solved a problem, you can have a staff member look it over for further advice.

  • We post lab solutions with extra information and ways of solving.

Setup instructions #

Head to http://url.cs51.io/lab12 and follow the Lab Procedures.

Lab puzzle #

Consider the following function definition with a blank in it:

  let toggle =
    let b = ref false in
    fun () -> let c = !b in
              ________________________ ;;

It’s intended to have the following behavior:

# toggle () ;;
- : bool = true
# toggle () ;;
- : bool = false
# toggle () ;;
- : bool = true
# toggle () ;;
- : bool = false

Which of the following expressions would generate the intended behavior when used to fill in the blank in the toggle function definition? Check all that apply.

A. b := not c; c

B. b := not c, not c

C. b := c; c

D. b := not c; not c

E. b := not c; not !b

F. c; b := not c

G. b := !c; not c

H. not c; b := not c

I. b := not c; !b

J. b := c; not c