Learning about a Function through Error Messages

1 Type triangle into the Interactions Area of WeScheme and hit "Enter". What do you learn?

2 We know that all functions will need an open parenthesis and at least one input! Type (triangle 80) in the Interactions Area and hit Enter/return. Read the error message. What hint does it give us about how to use this function?

3 Using the hint from the error message, experiment until you can make a triangle. What is the contract for triangle?

What Kind of Error is it?

  • syntax errors - the computer cannot make sense of the code because of unclosed strings, missing commas or parentheses, etc.

  • contract errors - the function isn’t given what it needs (the wrong type or number of arguments are used)

4 In your own words, the difference between syntax errors and contract errors is:

Finding Mistakes with Error Messages

The following lines of code are all BUGGY! Read the code and the error messages below. See if you can find the mistake WITHOUT typing it into WeScheme.

5 (triangle 20 "solid")

triangle: expects 3 arguments, but given 2: 20 solid at: line 1, column 0, in <interactions>

This is a contract / syntax error. The problem is that

6 (triangle "solid" "red" 20)

triangle: expects a non-negative number as 1st argument, but given: solid; other arguments were: red 20 at: line 1, column 0, in <interactions>

This is a contract / syntax error. The problem is that

7 (triangle 20 40 "solid" "red")

triangle: expects 3 arguments, but given 4: 20 40 solid red at: line 1, column 0, in <interactions>

This is a contract / syntax error. The problem is that

8 (triangle 20 solid "red")

solid: this variable is not defined at: line 1, column 0, in <interactions>

This is a contract / syntax error. The problem is that

(triangle 20 "striped" "red")

triangle: expects a style ("solid" / "outline") or an opacity value [0-255]) as 2nd argument, but given: "striped"; other arguments were: 20 "red" at: line 1, column 0, in <interactions>

This is a contract / syntax error. The problem is that

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.