[plt-scheme] slightly misleading error message

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Mon Dec 18 19:06:16 EST 2006


On Sat, 16 Dec 2006, Prabhakar Ragde wrote:

> I was checking whether mutation of parameters is forbidden in Advanced 
> Student (which it should be, because the semantics don't explain it)

Hi Prabhakar,

The book does mention it in the third restriction in the Grammar section:

    3.  A set!-expression must occur in the lexical scope of a define that 
introduces the set!-expression's left-hand side.

     http://htdp.org/2003-09-26/Book/curriculum-Z-H-47.html#node_sec_38.2



> and my attempt to do so did result in an error message, but the message 
> was:
>
> set!: expected a defined name after `set!', but found a function argument 
> name
>
> with the first "n" in (set! n (add1 n)) highlighted. This is in v360. --PR

That sounds like a correct error message to me.  What part do you feel is 
misleading about it?

It's saying that it would like to see something like:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define gensym
   (local
       [(define n 0)
        (define (next)
          (begin (set! n (add1 n))
                 (string->symbol
                  (format "g~a" n)))
          )]
     next))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

where 'n' is a defined name.  Here, the SET! is being used in a context 
where the left hand side, 'n', is scoped by a DEFINE.


On the other hand:

;;;;;;;;;;;;;;;;;;;;;
(define (++ n)
   (begin
     (set! n (add1 n))
     n))
;;;;;;;;;;;;;;;;;;;;;

shows that error message:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
set!: expected a defined name after `set!', but found a function argument 
name in: n
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

because the 'n' here is introduced as a function argument, and not one 
that was introduced by the DEFINE form.



Best of wishes!


Posted on the users mailing list.