COMP203: Assignment 2


Please include your full name and the assignment number in your document. Please submit your assignment through Blackboard's assignment manager in the form of a text (.txt) file.

  1. Write a procedure hexagon that accepts a number (say, :size) as input and draws a hexagon with that side length.
  2. Write a procedure hexpicture that uses your hexagon procedure to draw hexagons of different size that together make up a picture (Here are some examples using squares: example 1, example 2).
  3. Read the textbook's rules for nonsense plumbing diagrams on page 37 (in particular, in these examples you can tell how many inputs a procedure accepts by looking at its name) then draw the plumbing diagram for:
    with3 test2 [a b] [c d] [e f] [g h]
    
  4. On page 56 of the text the author proposes replacing the old converse procedure on page 44:
    to converse
    print [Please type your full name.]
    halves readlist
    end
    
    to halves :name
    print sentence [Your first name is] first :name
    print sentence [Your last name is] last :name
    end
    
    with the following:
    to new.converse
    local "name
    print [Please type your full name.]
    make "name readlist
    print sentence [Your first name is] first :name
    print sentence [Your last name is] last :name
    end
    
    Which version of converse do you prefer -- the one that requires two separate procedures in order to run, or the one that requires a local variable name in order to run? Give reasons for your preference.

  5. The variable name is not defined in the procedure halves2 below; try running halves2. Now run procedure converse2. Note that halves2 is a subprocedure of converse2 -- why doesn't halves2 produce an error message when run from converse2?
    to converse2
    local "name
    print [Please type your full name.]
    make "name readlist
    halves2
    end
    
    to halves2
    print sentence [Your first name is] first :name
    print sentence [Your last name is] last :name
    end
    
    Hint: Read the section on "Scope of Variables" that starts on page 49.
Bonus (5 pts) Write the helper procedure sc1 described on page 54 of the text.