Lazy Racket

► |  | Lazy Racket

1 | Lazy Forms and Functions
2 | Forcing Values

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

9.1
Racket
top contents ← prev up next →

# 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.

> syntax parameterize

Lazy variant of parameterize.

> syntax define-values

Lazy variant of define-values.

> syntax let-values

Lazy variant of let-values.

> syntax let*-values

Lazy variant of let*-values.

> syntax letrec-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.

> value values : procedure?

Lazy variant of values.

> value make-struct-type : procedure?

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*.

> value vector : procedure?

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.

> value set-mcar! : procedure?

Lazy variant of set-mcar!.

> value set-mcdr! : procedure?

Lazy variant of set-mcdr!.

> value vector-set! : procedure?

Lazy variant of vector-set!.

> value set-box! : procedure?

Lazy variant of set-box!.

> value error : procedure?

Lazy variant of error.

> value printf : procedure?

Lazy variant of printf.

> value fprintf : procedure?

Lazy variant of fprintf.

> value display : procedure?

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?.

> value equal? : procedure?

Lazy variant of equal?.

> value list? : procedure?

Lazy variant of list?.

> value length : procedure?

Lazy variant of length.

> value list-ref : procedure?

Lazy variant of list-ref.

> value list-tail : procedure?

Lazy variant of list-tail.

> value append : procedure?

Lazy variant of append.

> value map : procedure?

Lazy variant of map.

> value for-each : procedure?

Lazy variant of for-each.

> value andmap : procedure?

Lazy variant of andmap.

> value ormap : procedure?

Lazy variant of ormap.

> value member : procedure?

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.

> value reverse : procedure?

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.

> value caaaar : procedure?

Lazy variant of caaaar.

> value caaadr : procedure?

Lazy variant of caaadr.

> value caadar : procedure?

Lazy variant of caadar.

> value caaddr : procedure?

Lazy variant of caaddr.

> value cadaar : procedure?

Lazy variant of cadaar.

> value cadadr : procedure?

Lazy variant of cadadr.

> value caddar : procedure?

Lazy variant of caddar.

> value cadddr : procedure?

Lazy variant of cadddr.

> value cdaaar : procedure?

Lazy variant of cdaaar.

> value cdaadr : procedure?

Lazy variant of cdaadr.

> value cdadar : procedure?

Lazy variant of cdadar.

> value cdaddr : procedure?

Lazy variant of cdaddr.

> value cddaar : procedure?

Lazy variant of cddaar.

> value cddadr : procedure?

Lazy variant of cddadr.

> value cdddar : procedure?

Lazy variant of cdddar.

> value cddddr : procedure?

Lazy variant of cddddr.

> value first : procedure?

Lazy variant of first.

> value second : procedure?

Lazy variant of second.

> value third : procedure?

Lazy variant of third.

> value fourth : procedure?

Lazy variant of fourth.

> value fifth : procedure?

Lazy variant of fifth.

> value sixth : procedure?

Lazy variant of sixth.

> value seventh : procedure?

Lazy variant of seventh.

> value eighth : procedure?

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.

> value empty? : procedure?

Lazy variant of empty?.

> value foldl : procedure?

Lazy variant of foldl.

> value foldr : procedure?

Lazy variant of foldr.

> value last-pair : procedure?

Lazy variant of last-pair.

> value remove : procedure?

Lazy variant of remove.

> value remq : procedure?

Lazy variant of remq.

> value remv : procedure?

Lazy variant of remv.

> value remove* : procedure?

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.

> value filter : procedure?

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.

> value boolean=? : procedure?

Lazy variant of boolean=?.

> value symbol=? : procedure?

Lazy variant of symbol=?.

> value compose : procedure?

Lazy variant of compose.

> value build-list : procedure?

Lazy variant of build-list.

> value take : procedure?

Lazy variant of take.

> value identity : procedure?

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.
top contents ← prev up next →