1

I'm just starting to write in scheme in DrRacket. However, like we all probably know, those small changes in syntax always mess us up!

I believe my error is in the and conditional. If someone could take a look and tell me what's wrong that would be great!

; in-range?: int int list of numbers --> boolean
(define in-range?
  (lambda (a b s)
    (cond [(null? s) #t] ;List is empty
          [(null? a) #f]
          [(null? b) #f]
          [((and >= (car s)) ((a) <= (car s)) (b)) (in-range? (a) (b) (cdr s))]
          [else #f]
     )))
CKneeland
  • 119
  • 3
  • 14
  • I'm wondering why you have `null?` checks on `a` and `b`, because the signature says `a` and `b` are integers, not lists – Alex Knauth Sep 16 '20 at 20:09
  • To return false if they're empty, I changed it a few minutes ago after realizing the program doesn't even go if they're empty anyways. – CKneeland Sep 16 '20 at 20:16

1 Answers1

3

Imagine this form:

(test a b)

You can see it is an application because of the parentheses when test is not a syntax operand. Then test is evaluated and the expected outcome is a procedure that can be called with the evaluated arguments a and b.

You have this as the only epression in a cond term:

((and >= (car s)) ((a) <= (car s)) (b)) (in-range? (a) (b) (cdr s))

This is an application. (and >= (car s)) ((a) <= (car s)) (b)) is not a syntax operand. Then it is evaluated and the expected outcome is a procedure that takes at least one argument, the evaluation of (in-range? (a) (b) (cdr s)).

Since the expression is and which is a syntax operand we know it will either be #f or #t and you should have gotten an error like Application: not a procedure

Parentheses around something in Scheme is like parentheses after something in algol languages like C# and JavaScript. Imagine this expression:

((a.car >=)(), (<= a() s.car)())(in-range(a(), b(), s.cdr))

Lots of syntax errors there in JavaScript too :-o

Sylwester
  • 47,942
  • 4
  • 47
  • 79