#lang racket ; Common Racket Bugs: ; application: not a procedure; ; expected a procedure that can be applied to arguments ; given: ... ; arguments...: ... ; tl;dr: remove parentheses around variable names, remove extra parentheses ; ------------------------------------------------------------------------------------------- ; CORE PROBLEM: ; ------------------------------------------------------------------------------------------- ; This is one of the more common bugs that novices to Racket will run into. ; So what does it mean? ; Well the short answer is that you probably have parentheses somewhere you don't need them ; In Racket, there should only be parentheses around procedure calls; a common mistake ; is to put parentheses around variable names, see example below: (define (own-length lst) (cond [(empty? (lst)) 0] [else (+ 1 (own-length (rest lst)))])) (own-length '(1 3 4 5)) ; Trying running this code! ; The nice thing with this particular bug is that Dr. Racket is really helpful in ; identifying where you have those extra parentheses. In fact, the place where the ; extra parentheses are should be highlighted in red. ; Most of the time, fixing this bug is as easy as getting rid of the parentheses ; around the highlighted region. Try fixing the code above yourself! ; To fix this particular example, all you have to do with remove the parentheses around (lst) ; in the base case of own-length; the line [(empty? (lst)) 0] should be [(empty? lst) 0] instead ; The key takeaway from this bug is that in Racket, parentheses matter a lot! You can't have ; any extra sets of parentheses, as any time Racket sees a parentheses, it's going to try to ; call a procedure. ; ------------------------------------------------------------------------------------------- ; MORE COMPLICATED EXAMPLE: ; ------------------------------------------------------------------------------------------- ; In fact, you might see a bug like this in your code: (define (own-length2 lst) (cond [(empty? lst) 0] [else (+ 1 ((own-length2 (rest lst))))])) (own-length2 '(1 2 3)) ; Trying running this code! ; Here, it's a bit more tricky, because own-length is a procedure after all, so you do need ; parentheses around it. However, there are simply too many sets of parentheses. To fix this bug, ; remove the extra set of parentheses from the highlighted region. ; ------------------------------------------------------------------------------------------- ; Feedback: ; ------------------------------------------------------------------------------------------- ; Did this help you fix your bug? If not, feel free to shoot us an e-mail or come to ; office hours. You can also send feedback about this help file to: nathan.lin@yale.edu ; Thanks!