Learning about a Function through Error Messages

1 Type triangle into the Interactions Area of code.pyret.org (CPO) 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 - when the computer cannot make sense of the code because of unclosed strings, missing commas or parentheses, etc. contract errors - when 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 Pyret.

5 triangle(20, "solid" "red")

Pyret didn’t understand your program around

triangle(20, "solid" "red")

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

6 triangle(20, "solid")

This application expression errored:

triangle(20, "solid")

2 arguments were passed to the operator. The operator evaluated to a function accepting 3 parameters. An application expression expects the number of parameters and arguments to be the same.

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

7 triangle(20, 10, "solid", "red")

This application expression errored:

triangle(20, 10, "solid", "red")

4 arguments were passed to the operator. The operator evaluated to a function accepting 3 parameters. An application expression expects the number of parameters and arguments to be the same.

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

8 triangle (20, "solid", "red")

Pyret thinks this code is probably a function call:

triangle (20, "solid", "red")

Function calls must not have space between the function expression and the arguments.

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.