0
votes

I am writing a function, try-weak-cues, to select a response from a large set of responses. This program is essentially a conversation with the user.

(define try-weak-cues
        (lambda (sentence context)
        (define helper
           (lambda(list-of-pairs)
          (define helper2
            (lambda(list-of-pairs context)
              (cond((null? list-of-pairs)
                  (cond((null? list-of-pairs) '())
                       ((any-good-fragments?(cue-part(car list-of-pairs))sentence) (helper2(cdr(car list-of-pairs))context))
                        (else(helper(cdr list-of-pairs)))))))))
                       (helper *weak-cues*))))

Below is the list of responses that the function is supposed to pull from:

 (define *weak-cues*
  '( ( ((who) (whos) (who is))
       ((first-base)
           ((thats right) (exactly) (you got it)
        (right on) (now youve got it)))
       ((second-base third-base)
           ((no whos on first) (whos on first) (first base))) )
     ( ((what) (whats) (what is))
       ((first-base third-base)
       ((hes on second) (i told you whats on second)))
       ((second-base)
       ((right) (sure) (you got it right))) )
     ( ((whats the name))
       ((first-base third-base)
       ((no whats the name of the guy on second)
        (whats the name of the second baseman)))
       ((second-base)
    ((now youre talking) (you got it))))
   ))

The error:

define: bad syntax (multiple expressions after identifier) in: (define helper (lambda (list-of-pairs) (define helper2 (lambda (list-of-pairs context) (cond ((null? list-of-pairs) (cond ((null? list-of-pairs) (quote ())) ((any-good-fragments? (cue-part (car list-of-pairs)) sentence) (helper2 (cdr (car list-of-pairs)) context)) (else (helper (cdr list-of-pairs))))))))) (helper weak-cues))

1

1 Answers

8
votes

The problem is that, when you define an internal procedure inside the body of a lambda, you have to write an expression after the definition, typically calling the internal procedure. For example, this is wrong:

(define f
  (lambda (x)
    (define g
      (lambda (y)
        <body 1>))))

But this is correct, notice how after the inner lambda definition there's a <body 2> part:

(define f
  (lambda (x)
    (define g
      (lambda (y)
        <body 1>))
    <body 2>))

Also, your code will be much easier to debug if you avoid this style of procedure definition:

(define f
  (lambda (x)
    <body>))

It'll be shorter and clearer like this:

(define (f x)
  <body>)

Now, back to your code. After fixing the formatting and switching to the shorter procedure definition syntax, your code will look like this:

(define (try-weak-cues sentence context)
  (define (helper list-of-pairs)
    (define (helper2 list-of-pairs context)
      (cond ((null? list-of-pairs)
             (cond ((null? list-of-pairs) '())
                   ((any-good-fragments? (cue-part (car list-of-pairs)) sentence)
                    (helper2 (cdr (car list-of-pairs)) context))
                   (else (helper (cdr list-of-pairs)))))))
    <missing body>)
  (helper *weak-cues*))

Now it's clear that the body of helper is missing, after the inner definition of helper2 you didn't write anything. Possibly you intended to call helper2 at that point, but your code is confusing enough as it is and I can't guess what to write in the missing body, it's up to you.