Practice Problem:   Back to ice cream

Practice Problem: Back to ice cream

Here’s the ice cream program again. Imagine that you had this entered in the definitions window:

  include image

  

  SCOOP-SIZE = 15

  

  cone = flip-vertical(triangle(SCOOP-SIZE * 2, "solid", "tan"))

  

  overlay-xy(circle(SCOOP-SIZE, "solid", "pink"),

    0, 25,

    overlay-xy(circle(SCOOP-SIZE, "solid", "green"),

      0, 25,

      cone))

  

  # what would happen if we entered each of the following into the

  # interactions window BEFORE pressing Run?

  

  circle(15, "solid", "red")

  circle(SCOOP-SIZE, "solid", "red")

  cone = triangle(30, "solid", "blue")

  

  # what would happen if we entered each of the following into the

  # interactions window AFTER pressing Run?

  

  SCOOP-SIZE

  SCOOP

  cone = triangle(30, "solid", "blue")

To check your understanding of these how Pyret evaluates programs, ask yourself what happens in each of the following situations:

  • You run the ice-cream-cone program, then type scoop in the interactions window

  • You run the ice-cream-cone program, then type "scoop" in the interactions window

  • You run the ice-cream-cone program, then type scoop-size + 5 in the interactions window

  • You run the ice-cream-cone program, then type scoop-size + cone-size in the interactions window

  • You enter flavor = "strawberry" in the interactions window, hit run, then enter flavor in the interactions window.

  • You run the ice-cream-cone program, then type scoop-size = 10 in the interactions window