Lazy Racket
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
8.15.0.8

Lazy Racket🔗ℹ

Eli Barzilay

 #lang lazy package: 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 racket/base and racket/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🔗ℹ

syntax

lambda

Lazy variant of lambda.

syntax

define

Lazy variant of define.

syntax

let

Lazy variant of let.

syntax

let*

Lazy variant of let*.

syntax

letrec

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.

syntax

if

Lazy variant of if.

syntax

set!

Lazy variant of set!.

syntax

begin

Lazy variant of begin.

syntax

begin0

Lazy variant of begin0.

syntax

when

Lazy variant of when.

syntax

unless

Lazy variant of unless.

syntax

cond

Lazy variant of cond.

syntax

case

Lazy variant of case.

Lazy variant of values.
Lazy variant of make-struct-type.

value

cons : procedure?

Lazy variant of cons.

value

list : procedure?

Lazy variant of list.

value

list* : procedure?

Lazy variant of list*.
Lazy variant of vector.

value

box : procedure?

Lazy variant of box.

value

and : procedure?

Lazy variant of and.

value

or : procedure?

Lazy variant of or.
Lazy variant of set-mcar!.
Lazy variant of set-mcdr!.
Lazy variant of vector-set!.
Lazy variant of set-box!.

value

error : procedure?

Lazy variant of error.
Lazy variant of printf.
Lazy variant of fprintf.
Lazy variant of display.

value

write : procedure?

Lazy variant of write.

value

print : procedure?

Lazy variant of print.

value

eq? : procedure?

Lazy variant of eq?.

value

eqv? : procedure?

Lazy variant of eqv?.
Lazy variant of equal?.

value

list? : procedure?

Lazy variant of list?.
Lazy variant of length.
Lazy variant of list-ref.
Lazy variant of list-tail.
Lazy variant of append.

value

map : procedure?

Lazy variant of map.
Lazy variant of for-each.
Lazy variant of andmap.

value

ormap : procedure?

Lazy variant of ormap.
Lazy variant of member.

value

memq : procedure?

Lazy variant of memq.

value

memv : procedure?

Lazy variant of memv.

value

assoc : procedure?

Lazy variant of assoc.

value

assq : procedure?

Lazy variant of assq.

value

assv : procedure?

Lazy variant of assv.
Lazy variant of reverse.

value

caar : procedure?

Lazy variant of caar.

value

cadr : procedure?

Lazy variant of cadr.

value

cdar : procedure?

Lazy variant of cdar.

value

cddr : procedure?

Lazy variant of cddr.

value

caaar : procedure?

Lazy variant of caaar.

value

caadr : procedure?

Lazy variant of caadr.

value

cadar : procedure?

Lazy variant of cadar.

value

caddr : procedure?

Lazy variant of caddr.

value

cdaar : procedure?

Lazy variant of cdaar.

value

cdadr : procedure?

Lazy variant of cdadr.

value

cddar : procedure?

Lazy variant of cddar.

value

cdddr : procedure?

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.

value

first : procedure?

Lazy variant of first.
Lazy variant of second.

value

third : procedure?

Lazy variant of third.
Lazy variant of fourth.

value

fifth : procedure?

Lazy variant of fifth.

value

sixth : procedure?

Lazy variant of sixth.
Lazy variant of seventh.
Lazy variant of eighth.

value

rest : procedure?

Lazy variant of rest.

value

cons? : procedure?

Lazy variant of cons?.

value

empty : procedure?

Lazy variant of empty.
Lazy variant of empty?.

value

foldl : procedure?

Lazy variant of foldl.

value

foldr : procedure?

Lazy variant of foldr.
Lazy variant of last-pair.
Lazy variant of remove.

value

remq : procedure?

Lazy variant of remq.

value

remv : procedure?

Lazy variant of remv.
Lazy variant of remove*.

value

remq* : procedure?

Lazy variant of remq*.

value

remv* : procedure?

Lazy variant of remv*.

value

memf : procedure?

Lazy variant of memf.

value

assf : procedure?

Lazy variant of assf.
Lazy variant of filter.

value

sort : procedure?

Lazy variant of sort.

value

true : procedure?

Lazy variant of true.

value

false : procedure?

Lazy variant of false.
Lazy variant of boolean=?.
Lazy variant of symbol=?.
Lazy variant of compose.
Lazy variant of build-list.

value

take : procedure?

Lazy variant of take.

Lazy identity function.

value

cycle : procedure?

Creates a lazy infinite list that repeats its input arguments in order.

2 Forcing Values🔗ℹ

 (require lazy/force) package: lazy

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

procedure

(! expr)  any/c

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

procedure

(!! expr)  any/c

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

procedure

(!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.

procedure

(!!list expr)  list?

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