Your list is not incorrect. When your argument is not a pair, for example (lambda xs body ...) or (define (fun . xs) body ...) , all your arguments fall into the list. For example, (fun 1 2 3) will do xs '(1 2 3) . Doing (list* '(1 2 3) '()) does '((1 2 3) , which you cancel by invoking your loop with car , which does it again '(1 2 3) .
In addition, your procedure works as intended. You can clear your procedure a bit, but since there are no lists that slide above the list that folds over the next two items, it won't get much smaller. Below is basically the same code, but the procedure that does the work (which if there was a grouped pair that you could use) and with named let as an iterator loop (which is syntactic sugar for letrec +) is abstracted, is abstracted.
(define (distance-between e1 . lst) (define (add-diff-acc e1 e2 acc) (+ (abs (- (map-node-x e1) (map-node-x e2))) (abs (- (map-node-y e1) (map-node-y e2))) acc)) (let iterate ((e1 e1) (lst lst) (acc 0)) (if (pair? lst) (let ((e2 (car lst))) (iterate e2 (cdr lst) (add-diff-acc e1 e2 acc))) acc)))
EDIT: About sugar syntax named let and letrec .
(let ((x 10) (y 19)) body)
is syntactic sugar for anonymous procedure call
((lambda (xy) body) 10 19)
A named let just gives this procedure a name, albeit with letrec , as it were, doing a recursive binding. you call it with the name you give, and the arguments will be what you supply instead of the initial value in let. I am used to them and prefer them today. It may take some time to get used to.
Most of the code we write is syntactic sugar for some lower-level materials. Macros are nested so that your letrec form can be reduced in the end lambdas. The whole procedure without syntactic sugar will look like this:
(define distance-between (lambda (e1 . lst) ((lambda (add-diff-acc) ((lambda (iterate e1 lst acc) ; emulate Y to substitute `letrec` (iterate iterate e1 lst acc)) (lambda (iterate e1 lst acc) (if (pair? lst) ((lambda (e2) (iterate iterate e2 (cdr lst) (add-diff-acc e1 e2 acc))) (car lst)) acc)) e1 lst 0)) (lambda (e1 e2 acc) (+ (abs (- (map-node-x e1) (map-node-x e2))) (abs (- (map-node-y e1) (map-node-y e2))) acc)))))