For some reason, many students are reluctant to actually read error messages. They click the "Check Syntax" button, get an error message, and start changing the program randomly in hopes that the result will pass a syntax check. Don't do this! Making random changes to your program is more likely to make it worse than better.
When you use "Check Syntax", DrScheme will paint various parts of your program different colors: black for predefined functions, bold-face black for cond, define, and a few other special words, blue for functions you've defined, green for variables you've defined, and (perhaps most importantly) red for words you use but haven't defined anywhere. If you see red in your code, even though "Check Syntax" didn't print an error message, there's probably something wrong. Most likely, it means you mis-spelled a name. Scheme (like most modern computer languages) cares about punctuation, spelling, and capitalization, so it thinks "MyFunction", "myfunction", and "my-function" are three unrelated names. Even worse, it thinks "my function" is two words, "my" and "function", neither of which has any connection to the other three unrelated names.
Once you've done a "Check Syntax", you'll also find another neat feature of DrScheme: when you hold the mouse over any word that you've defined, you see an arrow to where you defined it; when you hold the mouse over the defining appearance of a word, you see arrows to all the places that that definition is used. If any of these arrows point to a different place than you were expecting, figure out why; it may indicate an error in your program (most likely incorrectly-nested parentheses).
Another useful syntax-checking feature of DrScheme is the "Reindent All" command on the "Scheme" menu. This command tells DrScheme to change the indentation of all the lines of code in the definitions window to accurately reflect the nesting of parentheses. If you've written several arguments to the same function on separate lines, they should be lined up with one another vertically. Likewise, if the question and answer of a "cond" clause are on separate lines, they should be lined up with one another vertically, and all of the clauses should be lined up with one another vertically. If things are not indented the way you expect, it indicates that you have some misplaced parentheses. For example,
(define (interest-rate balance) (cond [(< balance 500.00) 0] [(< balance 1000.00 0.03) [(< balance 5000.00) 0.04]] [else 0.05]))The warning sign here is that what should be four clauses of the "cond" aren't lined up with one another: the third one is farther to the right than expected. Of course, you can delete a space to make it line up, but that doesn't change the fact that the program is incorrectly structured.
(define (interest-rate balance) (cond [(< balance 500.00) 0] [(< balance 1000.00 0.03)] [(< balance 5000.00) 0.04]] [else 0.05]))But now when you "Check Syntax", you get the error message "Clause is not in question-answer format".
(define (interest-rate balance) | |
(cond | [(< balance 500.00) 0] |
[(< balance 1000.00 0.03)] | |
[(< balance 5000.00) 0.04]] | |
[else 0.05])) |
(define (interest-rate balance) (cond [(< balance 500.00) 0] [(< balance 1000.00) 0.03) [(< balance 5000.00) 0.04]] [else 0.05]))Of course, now that you've fixed this, you get the error message "Parenthesis does not match":
(define (interest-rate balance) (cond [(< balance 500.00) 0] [(< balance 1000.00) 0.03) [(< balance 5000.00) 0.04]] [else 0.05]))which is simply because, now that the parentheses and brackets are in the correct places, the marked one should be a square bracket to match the square bracket at the beginning of the clause.
(define (interest-rate balance) (cond [(< balance 500.00) 0] [(< balance 1000.00) 0.03] [(< balance 5000.00) 0.04]] [else 0.05]))Another "Reindent All" to make sure things are correctly nested, and we get
(define (interest-rate balance) (cond [(< balance 500.00) 0] [(< balance 1000.00) 0.03] [(< balance 5000.00) 0.04]] [else 0.05]))which is correct.