0

I'm at beginning with Scheme. I'm trying to check equality of returning boolean value

(cond [(= (Test number) #t) 1])]

If my test function returns true, my main function should return 1. But I get contract violation error. Is there anybody could help me?

gd1
  • 11,300
  • 7
  • 49
  • 88
user3251925
  • 15
  • 1
  • 4

1 Answers1

1

= is only used to compare numbers. eq? would be the correct equality procedure if you really need to check if something really is #t.

Normally any value not #f is considered a true value and if that is ok you should do this:

(cond [(Test number) 1]
      [else 'else-case])

Your cond misses a default case, like the one I've added. In case your Test return #f you really need it or else the result is undefined.

A related question on SO is What is the difference between eq?, eqv?, equal?, and = in scheme?

Community
  • 1
  • 1
Sylwester
  • 47,942
  • 4
  • 47
  • 79