#lang racket ; Common Racket Bugs: ; "procedure-name": arity mismatch; ; the expected number of arguments does not match the given number ; expected: ... ; given: ... ; tl;dr: you have the wrong number of arguments for a particular procedure call ; ------------------------------------------------------------------------------------------- ; 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 called a procedure with the wrong number of arguments. ; This could be a procedure that you defined yourself, or a built-in Racket procedure. ; Either way, you called it with the wrong number of arguments, see example below: (define (own-length lst) (cond [(empty? lst) 0] [else (+ 1 (own-length (rest lst)))])) (own-length '(1 3 4 5) '(2 3 5)) ; Trying running this code! ; Like some others bugs in Racket, Dr. Racket is really helpful in identifying where the error ; is coming from in your code. In fact, the particular function call with the wrong number of ; arguments should be highlighted in red. ; You can fix this bug by adjusting your code so that the number of arguments provided matches ; what the procedure expects. In this case, (own-length) is a procedure that only takes 1 argument ; however the procedure call (own-length '(1 3 4 5) '(1 2 3)) is trying to call (own-length) with ; 2 arguments. Thus, to fix this bug, you would have to remove one of these lists. ; Something like (own-length '(1 3 4 5)) would work instead. ; ------------------------------------------------------------------------------------------- ; MORE COMPLICATED EXAMPLE: ; ------------------------------------------------------------------------------------------- ; (get-last-element lst) should return the last element in lst (define (get-last-element lst) (take-right lst)) (get-last-element '(1 2 3 4 5)) ; Trying running this code! ; Here, there is an arity mismatch error that comes up due to the usage of (take-right). ; (take-right) is a Racket procedure that allows you get the last few elements of a list. ; You might run into bugs like this when you use commands that you aren't familiar with. ; If you look at the error message, it says that 2 arguments were expected but only 1 was given. ; However, even though it says you need 2 arguments, you probably don't even know what they are ; supposed to be! ; In these cases you should definitely look in the Racket guide: https://docs.racket-lang.org/guide/ ; Look in the Racket guide for the (take-right) command. How would you fix the above code? ; You should be able to fix it by changing (take-right lst) to (take-right lst 1) ; ------------------------------------------------------------------------------------------- ; 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!