On 04/24/2014 10:20 AM, ntoro...@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 ⊥

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

Reply via email to