Coding in scheme requires a different mindset with not only composing backwards expressions but also with debugging errors. Today, I was coding a simple sorting algorithm for a list. I was reciving an error message that mentioned list while there weren’t any direct list calls.
;The procedure #[compiled-procedure 13 (“list” #x26) #x1a #x10349b102] has been called with 1 argument; it requires exactly 2 arguments.
One thing to notice: called with 1 argument; it requires exactly 2 arguments. That is a give away that you’ve missed argument somewhere, even if the code isn’t what is mentioned previously, as in this case, list.
(cond ((< (distance (list-ref (- (length pt-list) 1) ) origin) delta-distance) (append pt-list p-list) ) ((> (distance (list-ref 0) origin) delta-distance) (append p-list pt-list) ) (else (append (car parts) p-list (cdr parts)) ) )
Looking through that code, it isn’t really obvious what’s wrong. Distance takes two “points” and calculates the distance between them. Origin is point (0,0) and delta distance is previously calculated. The
pt-list was a list of points to sort through and the
p-list was a list-ized singular point for insertion. Confused yet? I was too.
Look at the innocent
list-ref though? How many arguments does that have? The documentation says it has two arguments. I realized I missed the list argument in the call to