“application: not a procedure” in binary arithmetic procedures

In this line, you’re calling multBins with (cons 0 x) and (rest y), and getting some result r, and then trying to call r:

((= (first y) 0) ((multBins (cons 0 x) (rest y))))
;                ^                              ^
;                +--- function application -----+

The same kind of thing is happening in the next line, where you’re calling addWithCarry with some arguments, getting a result r, and trying to call r:

(#t              ((addWithCarry x (multBins (cons 0 x) (rest y)) 0)))))
;                ^                                                 ^
;                +-------------- function application -------------+

Presumable the unapplicable value '(0 0 0 1 0 1 1) is being returned by one of these.

In a very simplified case, consider this transcript from the DrRacket REPL:

> (define (value)        ; a function that returns the 
    '(0 0 0 1 0 1 1))    ; same value that yours should

> (value)                ; calling it produces the value 
(0 0 0 1 0 1 1)

> ((value))              ; calling it and then calling
                         ; return value causes the same
                         ; error that you're seeing
; application: not a procedure;
; expected a procedure that can be applied to arguments
;  given: (0 0 0 1 0 1 1)
;  arguments...: [none]

You didn’t mention what editor/IDE/debugger you’re using, but some should have made this a bit easier to spot. For instance, when I load your code (minus the call to test, whose definition I don’t have, and with definitions of first and rest), DrRacket highlights the location of the offending call:

bad code highlighted in DrRacket IDE

While both of the problematic calls that I’ve pointed out need to be fixed, the error that you’re seeing right now is occurring in the second of the two.

Leave a Comment