0

I keep receiving "The object 5.32 is not applicable" after running (main 1 2) then inputting 2 and finally -1. 5.32 is the correct answer. It just throws the mentioned error. (Should return ;Value 5.32).

I think my issue may be in my tax function, but am unsure. Any suggestions?

(define (add total num)(+ total num))
(define (tax total) (* total 1.065))

(define (main total x) 
  (if (= x -1) 
     (tax total)
  ((let ((z (add total x)))(let ((y (read)))(main z y))))
  )
)

And yes, I've checked here and here, though neither location answers the question in a general format.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • This is not Common Lisp, it looks like Scheme. But you have some other parentheses problems. – Barmar Apr 05 '18 at 00:27
  • You have an extra set of parentheses around the first `let`. – Barmar Apr 05 '18 at 00:27
  • @Barmer thank you. Do you mind explaining why the extra parentheses caused the error? I'm new to Lisp and Scheme (thanks for mentioning that by the way), and genuinely want to learn it. –  Apr 05 '18 at 00:32

1 Answers1

2

You have an extra set of parentheses around the third expression in if. The syntax is:

(if <condition>
    <true-expression>
    <false-expression>)

but you wrote:

(if <condition>
    <true-expression>
    (<false-expression>))

Putting the expression in parentheses turns it into a procedure call, where it tries to use the value returned by let as a procedure.

There's also no need to use multiple lets, you can bind more than one variable at a time.

(define (main total x) 
  (if (= x -1) 
      (tax total)
      (let ((z (add total x))
            (y (read)))
          (main z y)))))
Barmar
  • 741,623
  • 53
  • 500
  • 612