[racket-dev] [plt] Push #28607: master branch updated

From: Neil Toronto (neil.toronto at gmail.com)
Date: Thu Apr 24 12:30:23 EDT 2014

On 04/24/2014 10:20 AM, ntoronto at racket-lang.org wrote:
> ntoronto has updated `master' from d30546cb7d to bee344f41d.
> :
> | Fix Plot for new undefined behavior: #<undefined> is not a truth value
> |
> | This is a nice example of why having #<undefined> as a language value is
> | generally a bad idea. Because in Scheme/Racket, everything that isn't
> | `refresh?` argument entirely - it was as if its value was always #t. Any
> | GUI change that was not meant to cause a refresh caused one anyway: a
> | silent performance error.
>
> [...]
>
>       (define/public (set-message msg #:refresh? [refresh? #t])
> -      (define refresh? (and refresh? (not (equal? msg message))))
> -      (set! message msg)
> -      (reset-message-timeout)
> -      (when refresh? (refresh)))
> +      (let ([refresh?  (and refresh? (not (equal? msg message)))])
> +        (set! message msg)
> +        (reset-message-timeout)
> +        (when refresh? (refresh))))

Somehow my log message got mangled. I'll show you that I can words!

The idea of the line

     (define refresh? (and refresh? (not (equal? msg message))))

is to optimize the case in which the message doesn't change, by not 
refreshing. But the RHS was always #<undefined>, which, as a truth 
value, is equivalent to #t. So the optimization was actually a 
pessimization: it effectively always made the incoming `refresh?` #t.

Feel free to use this as an example in papers. I would never have caught 
it without the new undefined semantics.

Thanks to Laurent for getting hit with it first. :)

Neil ⊥


Posted on the dev mailing list.