1 Lazy Forms and Functions
lambda
define
let
let*
letrec
parameterize
define-values
let-values
let*-values
letrec-values
if
set!
begin
begin0
when
unless
cond
case
values
make-struct-type
cons
list
list*
vector
box
and
or
set-mcar!
set-mcdr!
vector-set!
set-box!
error
printf
fprintf
display
write
print
eq?
eqv?
equal?
list?
length
list-ref
list-tail
append
map
for-each
andmap
ormap
member
memq
memv
assoc
assq
assv
reverse
caar
cadr
cdar
cddr
caaar
caadr
cadar
caddr
cdaar
cdadr
cddar
cdddr
caaaar
caaadr
caadar
caaddr
cadaar
cadadr
caddar
cadddr
cdaaar
cdaadr
cdadar
cdaddr
cddaar
cddadr
cdddar
cddddr
first
second
third
fourth
fifth
sixth
seventh
eighth
rest
cons?
empty
empty?
foldl
foldr
last-pair
remove
remq
remv
remove*
remq*
remv*
memf
assf
filter
sort
true
false
boolean=?
symbol=?
compose
build-list
take
identity
cycle
2 Forcing Values
!
!!
!list
!!list
Version: 5.1

Lazy Racket

Eli Barzilay

 #lang lazy

Lazy Racket is available as both a language level and a module that can be used to write lazy code. To write lazy code, simply use lazy as your module’s language:

  #lang lazy
  ... lazy code here...

Function applications are delayed, and promises are automatically forced. The language provides bindings that are equivalent to most of the mzscheme and scheme/list libraries. Primitives are strict in the expected places; struct constructors are lazy; if, and, or etc. are plain (lazy) functions. Strict functionality is provided as-is: begin, I/O, mutation, parameterization, etc. To have your code make sense, you should chain side effects in begins, which will sequence things properly. (Note: This is similar to threading monads through your code—only use begin where order matters.)

Mixing lazy and strict code is simple: you just write the lazy code in the lazy language, and strict code as usual. The lazy language treats imported functions (those that were not defined in the lazy language) as strict, and on the strict side you only need to force (possibly recursively) through promises.

A few side-effect bindings are provided as-is. For example, read and printf do the obvious thing—but note that the language is a call-by-need, and you need to be aware when promises are forced. There are also bindings for begin (delays a computation that forces all sub-expressions), when, unless, etc. There are, however, less reliable and might change (or be dropped) in the future.

There are a few additional bindings, the important ones are special forms that force strict behaviour—there are several of these that are useful in forcing different parts of a value in different ways, as described in Forcing Values.

1 Lazy Forms and Functions

Lazy variant of lambda.
Lazy variant of define.

Lazy variant of let.
Lazy variant of let*.
Lazy variant of letrec.
Lazy variant of parameterize.
Lazy variant of define-values.
Lazy variant of let-values.
Lazy variant of let*-values.
Lazy variant of letrec-values.
Lazy variant of if.
Lazy variant of set!.
Lazy variant of begin.
Lazy variant of begin0.
Lazy variant of when.
Lazy variant of unless.
Lazy variant of cond.
Lazy variant of case.

Lazy variant of values.
Lazy variant of make-struct-type.
Lazy variant of cons.
Lazy variant of list.
Lazy variant of list*.
Lazy variant of vector.
Lazy variant of box.
Lazy variant of and.
Lazy variant of or.
Lazy variant of set-mcar!.
Lazy variant of set-mcdr!.
Lazy variant of vector-set!.
Lazy variant of set-box!.
Lazy variant of error.
Lazy variant of printf.
Lazy variant of fprintf.
Lazy variant of display.
Lazy variant of write.
Lazy variant of print.
Lazy variant of eq?.
Lazy variant of eqv?.
Lazy variant of equal?.
Lazy variant of list?.
Lazy variant of length.
Lazy variant of list-ref.
Lazy variant of list-tail.
Lazy variant of append.
Lazy variant of map.
Lazy variant of for-each.
Lazy variant of andmap.
Lazy variant of ormap.
Lazy variant of member.
Lazy variant of memq.
Lazy variant of memv.
Lazy variant of assoc.
Lazy variant of assq.
Lazy variant of assv.
Lazy variant of reverse.
Lazy variant of caar.
Lazy variant of cadr.
Lazy variant of cdar.
Lazy variant of cddr.
Lazy variant of caaar.
Lazy variant of caadr.
Lazy variant of cadar.
Lazy variant of caddr.
Lazy variant of cdaar.
Lazy variant of cdadr.
Lazy variant of cddar.
Lazy variant of cdddr.
Lazy variant of caaaar.
Lazy variant of caaadr.
Lazy variant of caadar.
Lazy variant of caaddr.
Lazy variant of cadaar.
Lazy variant of cadadr.
Lazy variant of caddar.
Lazy variant of cadddr.
Lazy variant of cdaaar.
Lazy variant of cdaadr.
Lazy variant of cdadar.
Lazy variant of cdaddr.
Lazy variant of cddaar.
Lazy variant of cddadr.
Lazy variant of cdddar.
Lazy variant of cddddr.
Lazy variant of first.
Lazy variant of second.
Lazy variant of third.
Lazy variant of fourth.
Lazy variant of fifth.
Lazy variant of sixth.
Lazy variant of seventh.
Lazy variant of eighth.
Lazy variant of rest.
Lazy variant of cons?.
Lazy variant of empty.
Lazy variant of empty?.
Lazy variant of foldl.
Lazy variant of foldr.
Lazy variant of last-pair.
Lazy variant of remove.
Lazy variant of remq.
Lazy variant of remv.
Lazy variant of remove*.
Lazy variant of remq*.
Lazy variant of remv*.
Lazy variant of memf.
Lazy variant of assf.
Lazy variant of filter.
Lazy variant of sort.
Lazy variant of true.
Lazy variant of false.
Lazy variant of boolean=?.
Lazy variant of symbol=?.
Lazy variant of compose.
Lazy variant of build-list.
Lazy variant of take.

Lazy identity function.

Creates a lazy infinite list given a list of elements to repeat in order.

2 Forcing Values

 (require lazy/force)

The bindings of lazy/force are re-provided by lazy.

(! expr)  any/c
  expr : any/c
Evaluates expr strictly. The result is always forced, over and over until it gets a non-promise value.

(!! expr)  any/c
  expr : any/c
Similar to !, but recursively forces a structure (e.g: lists).

(!list expr)  list?
  expr : (or/c promise? list?)
Forces the expr which is expected to be a list, and forces the cdrs recursively to expose a proper list structure.

(!!list expr)  list?
  expr : (or/c promise? list?)
Similar to !list but also forces (using !) the elements of the list.