Learning about a Function through Error Messages

1 Type sort into the Interactions Area of the Animals Starter File and hit "Enter". What do you learn?

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

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)

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

Finding Mistakes with Error Messages

The code below is BUGGY! Read the code and the error messages, and see if you can catch the mistake WITHOUT typing the code into Pyret.

4 sort(animals-table, name , true)

The name name is unbound:

sort(animals-table, name , true)

It is used but not previously defined.

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

5 sort(animals-table, "name" , "true")

The Boolean annotation:
fun sort(t :: Table, col :: String, asc :: Boolean)
was not satisfied by the value

"true"

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

6 sort(animals-table "name" true)

Pyret didn’t understand your program around:

sort(animals-table "name" true)

You may need to add or remove some text to fix your program. Look carefully before the highlighted text. Is there a missing colon (:), comma (,), string marker ("), or keyword? Is there something there that shouldn’t be?

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

7 sort(animals-table, "name", true

Pyret didn’t expect your program to end as soon as it did:

sort(animals-table, "name", true

You may be missing an "end", or closing punctuation like ")" or "]" somewhere in your program.

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

8 sort (animals-table, "name", true)

Pyret thinks this code is probably a function call:

sort (animals-table, "name", true)

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.