1
votes

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.

1

1 Answers

1
votes

I'd guess integer-less? is part of your scheme's implementation and is called when < is comparing integers. If so, you would need to go looking at the source code of your scheme.

If that is the case then it might be complaining because it expects both the arguments of < to be integers, but at least one isn't. That may be because weight-b does not always return an integer.

I don't think (if (pair? mobile) ... has an alternate clause so if mobile is not a pair then the result of weight-b may be undefined (the exact behaviour depends on the version of scheme you're using).