[plt-scheme] v4 questions

From: Mark Engelberg (mark.engelberg at gmail.com)
Date: Mon Mar 31 02:18:40 EDT 2008

>  I looked at that, and what I see is a way to delay evaluation of
>  expressions in classes -- and that's an easy exercise using structs in
>  mzscheme.  Imitating the first example in the chapter:

As far as I know, the lazy keyword can be used for any immutable
variable, and is not just limited to expressions in classes, but I
can't readily find examples to prove that.

As I recall from my brief time working with Scala, Scala's evaluation
mechanism makes no distinction between variables and functions with no
arguments, so if a variable is bound to such a thunk, it automatically
evaluates when the variable is dereferenced.  (In other words, typing
thunk and thunk() is equivalent, although there's some extra syntax
you can use to get at the actual thunk rather than auto-evaluating it
if you absolutely need to).  They do this so that if you want to
change a class variable into an accessor method, you don't need to go
making changes elsewhere in your program in the way the member
variable is accessed.

My guess is that the lazy keyword essentially binds the variable to a
delay-like thunk, but no force is necessary because of the way all
thunks are auto-evaluated.


Posted on the users mailing list.