A user on stackoverflow had a question about this code:

(define list-sum-odd
  (lambda (list)
    (cond
      ((null? list) 0)
      ((odd? (car list)) (+ (car list) (list-sum-odd (cdr list))))
      (list-sum-odd (cdr list)))))


(list-sum-odd '(3 4 5))

... which signalled an error. In #lang racket, you get

"+: expects type <number> as 2nd argument, given: '(5); other arguments were: 3"

... which is the right error for #lang racket. The response showed him that 
he'd forgotten the "else" in his last clause.

"Ho Ho!" thought I. "Beginner Student Racket will give a much better error 
message." Actually, though, the error message was much worse: it highlighted 
the id "list-sum-odd" in what should have been the 'else' case, and wrote:

"list-sum-odd: expected a function call, but there is no open parenthesis 
before this function"

... which is really terrible, because there *IS* a parenthesis right before the 
function name. 

I can see perfectly clearly how this arises as the composition of macros; would 
it make sense for the 'cond' macro to check to see whether its test expression 
is a bare function name before rearranging the pieces and continuing with 
expansion?



Specifically, it looks like such a check could be inserted on line 1316 of 
teach.rkt, in this code:

 [(question answer)
                           (with-syntax ([verified (stepper-ignore-checker 
(syntax (verify-boolean question 'cond)))])
                             (syntax/loc clause (verified answer)))]

... where you could issue an error message for questions that are ids that are 
bound to user-defined functions--we have this information, right?

John

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev

Reply via email to