Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Attempted to call INTEGER as a function
#1
code from the book:

(define (square x ) (* x x))
(define (sum_of_square x y )
(+ (square x) (square y)))

(define (func a )
(sum_of_square( + (a 1) (* a 2))))

(inspect (func 5))

result :

(func 5) is <exception nonFunction>
------------------------------------
EXCEPTION: nonFunction
file squarez.scm,line 8: attempted to call INTEGER as a function

How may I fix it so that the result is 136 (the book result)
Reply
#2
(sum_of_square( + (a 1) (* a 2))))

That (a 1) looks bogus.
Reply
#3
(09-03-2017, 12:47 AM)lusth Wrote: (sum_of_square( + (a 1) (* a 2))))

That (a 1) looks bogus.
It does........
Reply
#4
I'm also having this error come up, though everything I'm reading says that the code should be right. The line I have the error raising from is: 

(else 1)

I've confirmed that my parenthesis match where expected throughout my code, paying close attention to my cond block. When running scam with the -t option, it points me to my args file, -r points me to the line above. Where should I be looking for this error, or have I completely misunderstood how conditionals work in scam?
Reply
#5
Are you getting an error like:

EXCEPTION: nonFunction
file main.lib,line 98: attempted to call symbol #t as a function

If so, it is likely your else is outside of your cond.
Reply
#6
(09-06-2017, 11:12 PM)lusth Wrote: Are you getting an error like:

EXCEPTION: nonFunction
file main.lib,line 98: attempted to call symbol #t as a function

If so, it is likely your else is outside of your cond.

No, sir. My exact error is:

EXCEPTION: nonFunction
file task3.scm,line 14: attempted to call Integer as a function
Reply
#7
Then it appears you are calling the result of your cond (if the else hits, the result of the cond is 1) as a function. Do you have an extra set of parens anywhere?
Reply
#8
(09-06-2017, 11:27 PM)lusth Wrote: Then it appears you are calling the result of your cond (if the else hits, the result of the cond is 1) as a function. Do you have an extra set of parens anywhere?
Turns out, yes, there was an extra set of parens enclosing the whole code block. Thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)