Reputation: 307
I am trying to implement a function that tells if the parameter is power of 2. Here is what I have
(define (powof2 x) (cond
[(and (even? x) (> x 1)) ((powof2 (/ x 2)))]
[else (equal?(x 1))]))
But when I try to run it with parameter 12 I get the error saying: Error: 3 is not a function [powof2, powof2, powof2, (anon)]
Any help?
Thanks!
Upvotes: 0
Views: 88
Reputation: 18927
Ah those parenthesis ;-)
(define (powof2 x)
(cond
[(and (even? x) (> x 1)) (powof2 (/ x 2))]
[else (= x 1)]))
Note that in the 3rd line and 4th line you had an extra pair of parenthesis, and in the 4th line that you should use =
to compare numbers.
Upvotes: 2