[racket] iterative lazy space-safe or not?
// Maybe I should go off-list if this is only of interest to two of us...
Here is what I've found in OCaml, Scala and F#.
(They are not latest release, though. I used REPL.)
I didn't get what I thought from Scala.
OCaml (3.11.2): Exception memorized, black hole is an exception
# let x = ref 0;;
# let y = lazy (if !x = 0 then 1/0 else 1);;
# Lazy.force y;;
Exception: Division_by_zero.
# x := 1;;
# Lazy.force y;;
Exception: Division_by_zero.
# let rec z = lazy (Lazy.force z);;
# Lazy.force z;;
Exception: CamlinternalLazy.Undefined.
F# (1.9.7.8): Exception memorized, black hole is an exception
> let x = ref 0;;
> let y = lazy (if !x = 0 then 1/0 else 1);;
> y.Force ();;
Exception: Division by zero
> x := 1;;
> y.Force ();;
Exception: Division by zero
> let rec z: Lazy<int> = lazy (z.Force ());;
> z.Force ();;
Exception: a lazy value was accessed during its own initialization
Scala (2.8.0): Exception not memorized,
black hole diverges with repeated reinitialization
scala> var x = 0
scala> lazy val y = (if (x == 0) 1/0 else 1)
scala> y
java.lang.ArithmeticException: / by zero
scala> x = 1
scala> y
res1: Int = 1
scala> lazy val y: Int = {println ("hi"); y}
scala> y
hi
hi
hi
... (untill java.lang.StackOverflowError)
For Haskell I only know that [mfix] raises an exception for black holes.
But "A semantics for imprecise exceptions" paper writes that they
memorize exceptions: "if the thunk is evaluated again, the same
exception will be raised again, which is as it should be."
(I've not yet managed to try this out myself.)
Keiko