[racket-dev] Catching the undefined value

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sat Apr 19 15:26:18 EDT 2014

Ah. There are other approaches to this problem that result in
compile-time errors for such programs. Maybe the TR guys will adopt
one or figure out a better one! But for regular ole Racket, we're
stuck with a runtime error, I'm afraid.

Robby

On Sat, Apr 19, 2014 at 2:04 PM, Gustavo Massaccesi <gustavo at oma.org.ar> wrote:
>>> (letrec ([x (if #t 8 x)]) x) ;==>8
>
> It was a mistake. I thought that the “x: undefined; ...” error was an
> expansion-time error, not a run-time error.
>
> (I expected an error, because the x in the else part is “undefined”,
> even if it’s never accessed.)
>
> Gustavo
>
>
> On Sat, Apr 19, 2014 at 1:02 PM, Robby Findler
> <robby at eecs.northwestern.edu> wrote:
>> These seem correct to me. What were you expecting (and why?).
>>
>> Robby
>>
>>
>> On Saturday, April 19, 2014, Gustavo Massaccesi <gustavo at oma.org.ar> wrote:
>>>
>>> I found another problem with the optimizer and the new undefined behavior.
>>>
>>> (letrec ([x (if #t 8 x)]) x) ;==>8
>>>
>>> I also consider this correct in a strange sense :).
>>>
>>> Gustavo
>>>
>>>
>>> Welcome to Racket v6.0.1.4.
>>> > (letrec ([x x]) x)
>>> x: undefined;
>>>  cannot use before initialization
>>>   context...:
>>>    C:\Program Files\Racket-6.0.1.4\collects\racket\private\misc.rkt:87:7
>>> > (letrec ([x 5]) x)
>>> 5
>>> > (letrec ([x (if #t 8 x)]) x)
>>> 8
>>> > (letrec ([x (if #f 8 x)]) x)
>>> x: undefined;
>>>  cannot use before initialization
>>>   context...:
>>>    C:\Program Files\Racket-6.0.1.4\collects\racket\private\misc.rkt:87:7
>>> >
>>>
>>>
>>> On Wed, Apr 16, 2014 at 10:09 AM, Matthias Felleisen
>>> <matthias at ccs.neu.edu> wrote:
>>> >
>>> > Ah, too bad:
>>> >
>>> >> pkgs/racket-pkgs/racket-test/tests/racket/optimize.rktl
>>> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> >> --- OLD/pkgs/racket-pkgs/racket-test/tests/racket/optimize.rktl
>>> >> +++ NEW/pkgs/racket-pkgs/racket-test/tests/racket/optimize.rktl
>>> >> @@ -3416,5 +3416,16 @@
>>> >>           (read (open-input-bytes (get-output-bytes o))))))
>>> >>
>>> >> ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>> >> +;; Check that an unsufe opertion's argument is
>>> >> +;; not "optimized" away if it's a use of
>>> >> +;; a variable before definition:
>>> >> +
>>> >> +(err/rt-test (let ()
>>> >> +               (unsafe-fx+ x 1)
>>> >> +               (define x 3)
>>> >> +               x)
>>> >> +             exn:fail:contract:variable?)
>>> >> +
>>> >> +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>> >
>>> >
>>> > :-)
>>> >
>>> > On Apr 16, 2014, at 9:02 AM, Matthias Felleisen <matthias at ccs.neu.edu>
>>> > wrote:
>>> >
>>> >>
>>> >> On Apr 15, 2014, at 9:29 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
>>> >>
>>> >>> On 2014-04-15 18:13:31 -0400, claire alvis wrote:
>>> >>>> The push below includes changes to letrec expressions, internal
>>> >>>> definitions, units, classes, and certain ill-formed shared
>>> >>>> expressions so
>>> >>>> that they no longer leak the `undefined' value.
>>> >>>
>>> >>> This is great! (especially happy that TR, even with classes, doesn't
>>> >>> have to worry about #<undefined> anymore)
>>> >>>
>>> >>> BTW, I found this weird behavior:
>>> >>>
>>> >>> Welcome to Racket v6.0.1.3.
>>> >>> -> (require racket/unsafe/ops)
>>> >>> -> (let () (+ x 3) (define x 3) 5)
>>> >>> ; x: variable used before its definition [,bt for context]
>>> >>> -> (let () (unsafe-fx+ x 3) (define x 3) 5)
>>> >>> 5
>>> >>
>>> >>
>>> >> I consider this correct in a strange sense.
>>> >>
>>> >> Interestingly enough,
>>> >>
>>> >>> (let () (displayln  (unsafe-fx+ x 3)) (define x 3) 5)
>>> >> x: variable used before its definition
>>> >>  context...:
>>> >>   /Users/matthias/plt/racket/collects/racket/private/misc.rkt:87:7
>>> >>
>>> >> which is good too. I don't know how Claire and Matthew did this,
>>> >> but it's good :-)
>>> >> _________________________
>>> >>  Racket Developers list:
>>> >>  http://lists.racket-lang.org/dev
>>> >
>>> > _________________________
>>> >   Racket Developers list:
>>> >   http://lists.racket-lang.org/dev
>>> _________________________
>>>   Racket Developers list:
>>>   http://lists.racket-lang.org/dev


Posted on the dev mailing list.