0
(define subset? (lambda (st1 st2)
    (cond
        ((not (set? st1))
        (error "Your first argument is not a set!"))
        ((not (set? st2))
        (error "Your second argument is not a set!"))
        ((null? (st1)) #t)
        ((in? ((car st1) st2)) (subset? ((cdr st1) st2)))
        (else #f)
        )))

I have written this code to check whether the first list appears in the second, i.e. second contains the first. Everything seems fine to me but it says object bla bla (first list is shown) is not applicable.

Any help will be appreciated. Should be easy one, but couldn't see it.

bengongon97
  • 256
  • 2
  • 13

1 Answers1

1

You have several parenthesis issues, possibly because you think that the argument list should be wrapped in parentheses.
You should just write the arguments sequentially after the function's name.

The form

(define subset? (lambda (st1 st2) ...

can easily lead to this mistake, but the equivalent form

(define (subset? st1 st2) ...

looks like function application looks.

So, in

(in? ((car st1) st2))

you try to apply (car st1) to st2 and pass the result to in?; in

(subset? ((cdr st1) st2))

you try to apply (cdr st1) to st2 and pass the result to subset?; and in

(null? (st1))

you're trying to call st1 without any arguments and pass the result to null?.

The correct syntax is

(in? (car st1) st2)
(subset? (cdr st1) st2)
(null? st1)
molbdnilo
  • 64,751
  • 3
  • 43
  • 82