I'm doing exercise 2.29 from SICP, using MIT/GNU Scheme (Release 9.1.1). Currently I'm debugging following solution
(define (balanced mobile)
; weight-b returns weight of mobile if it is balanced, otherwise - negative value
(define (weight-b mobile)
(if (pair? mobile)
(let ((lb (weight-b (branch-structure (left-branch mobile))))) ; compute left balance
(if (< lb 0)
-1 ; left submobile is not balanced, so this mobile too
(let ((rb (weight-b (branch-structure (right-branch mobile))))) ; compute right balance
(display "rb ") (display lb) (newline) ; DEBUG log
(if (< rb 0)
-1 ; right submobile is not balanced, so this mobile too
(if (=
(* lb (branch-length (left-branch mobile)))
(* rb (branch-length (right-branch mobile)))
)
(+ lb rb) ; finally, completely balanced case, return total weight
-1 ; submobiles are balanced, but torques are different
)
)
)
)
)
)
mobile ; single weight is already balanced by itself
)
(> (weight-b mobile) 0)
)
It gives me error "The object ((1 5) (1 5)), passed as the first argument to integer-less?, is not the correct type." At first, from name integer-less?
assumed that it is problem with (< lb 0)
or (< rb 0)
, but I logged lb and rb, and they are integer.
My code does not call integer-less?
explicitly, so I'm not sure where to look then. Could you please tell what is ingeger-less?
, where to find it in my program, or in general, how to locate line number in Scheme code where error happened.
I tried integer-less?
in REPL, but it responds with "Unbound variable: integer-less?", and googling was not successful too.