0

Why would the Scheme interpreter demand numeric arguments for not?

In my case:

(not (= 1 2)) returned the following error:

-: contract violation
  expected: number?
  given: #f
  context...:
   stdin::1135: not

This is rather contrary to my 20-minute experience with the SICP, according to which not is a logical composition operator and its operands are supposed to be logical too.

Here comes the funniest part: the error is not reproducible. I know it sounds stupid, but I launched Racket once, got this error, re-launched it and the error was gone (i.e. not switched to returning proper logical values). Does anybody have an idea why might that happen? Is there something that I'm unaware of that affects Scheme's or Racket's behavior?

Note: I didn't modify the environment in any way, in neither of the cases. The only thing I did was enter the expression above.

Alex Agapov
  • 125
  • 7
  • Are you actually comparing 1 and 2, or some variables whose values you assumed to be 1 and 2? Or could there have been a typo or autocompletion to bitwise-not that would do a bit inversion rather than a logical negation and thus expect a number? – Joshua Taylor Apr 13 '16 at 13:09
  • Thank you for your reply! No variables were used; as I said, the environment was left untouched. Could you please elaborate on bitwise-not? I was under the impression that Scheme only has one kind of `not` operator, though I could have missed something. – Alex Agapov Apr 13 '16 at 13:41
  • You tagged with both Scheme and Racket, which usually means Racket, so I looked in the Racket documentation and found the function [bitwise-not](https://docs.racket-lang.org/reference/generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._bitwise-not%29%29). It was just a though that maybe some autocompletion or something might have used bitwise-not instead of not. But the error message doesn't look like that's what happened... – Joshua Taylor Apr 13 '16 at 14:13
  • I'd actually think this might be more like some kind of line-buffering issue, or maybe an accidental redefinition of `not`. – Joshua Taylor Apr 13 '16 at 14:14
  • 1
    The `-` in `-:` suggests to me the error is from the minus operator and not `not` ? – soegaard Apr 13 '16 at 15:06
  • @JoshuaTaylor yes, it seems this isn't the case. But I'm more and more inclined to think it was a line-buffering issue, as you said. Accidental redefinition is also possible - I can't really remember it now, though :) – Alex Agapov Apr 13 '16 at 15:33
  • 1
    @soegaard wow, that's a find. I didn't give it a thought then, but in this particular line no `-` operators were used. Weird stuff. – Alex Agapov Apr 13 '16 at 15:37
  • Are you using the terminal or emacs? – soegaard Apr 13 '16 at 15:50
  • @soegaard terminal – Alex Agapov Apr 13 '16 at 16:14
  • Do you still have the dots in `context...:` ? – soegaard Apr 13 '16 at 16:19
  • @soegaard yep. These are in every error message and indicate that the error occured in code from stdin (as far as I understand) – Alex Agapov Apr 13 '16 at 16:25
  • Ah! I thought the `...` meant something was omitted. I have no idea why you got the error. – soegaard Apr 13 '16 at 16:27
  • @soegaard :) Me too. But I'm strongly inclined to think it was my fault and I just forgot I modified the environment in some way. – Alex Agapov Apr 13 '16 at 16:34

1 Answers1

0

Just to say I did:

I tested (not (= 1 2)) in guile, gambit, chicken, drracket 6.4 and they all returned #t, as expected.

So there must have been some problem in your installation or environment. To find it we need more information.

Str.
  • 1,389
  • 9
  • 14