racket / htdp

Other
92 stars 70 forks source link

[ASL] Value of `set!` #162

Open a11ce opened 2 years ago

a11ce commented 2 years ago

The value of calling set! appears to be (some form of) void:

> (define x 1)
> (set! x 2)
(void)

but doesn't behave as void or (void):

> (void? (set! x 3))
#false
> ((set! x 3))
function call: expected a function after the open parenthesis, but received (void)

This is causing confusion for students because they have to use something like (begin (set! x y) (void)) even though it looks unnecessary.

a11ce commented 2 years ago

This looks like the same issue as #21. Here is an abridged concrete example from a course:

(define (evaluate-complex expr dict)
  ...
  [(eq? operator 'define)
           (begin (set! dictionary
                        (make-binding (second exp)
                                      (evaluate (third exp)
                                                d)
                                      dictionary))
                  (void))]
  ...)

(check-satisfied (evaluate '(define a 1)
                           dictionary)
                 void?)

Having set! (etc.) evaluate such that (void? (set! x 1)) may be easier in this case, but if that's unacceptable (per the last comment on #21), it should be explained somewhere that (void) (the output of set! in the REPL) is not the same as (void) (which produces a void value).