Lang¶
The base language library (import (lang)) provides the most bare-bones
standard scheme syntax and functions to get started.
Warning
This library is largely incomplete and not everything that scheme-rs has
to offer! Try out (import (rnrs)) for a more complete language and consult
the r6rs specification and
r6rs standard libraries specification.
define syntax¶
Defining variables¶
Defines a variable with the name variable and binds it to the result of expression
| Example: | |
|---|---|
Defining funtions¶
Defines a function. A function can have any number of arguments and optionally end
in . variable-name to express variable arity.
lambda syntax¶
The lambda keyword is used to define anonymous procedures. It has three key forms:
(lambda (⟨arg1⟩ ... ⟨argn⟩) ⟨body⟩)Defines an anonymous procedure that takesnarguments and applies them to body.(lambda (⟨arg1⟩ ... ⟨argn⟩ . ⟨var args⟩) ⟨body⟩)Defines an anonymous procedure that takes at leastnarguments and applies them to body. Any extra arguments are bound to⟨var args⟩as a list.(lambda ⟨args⟩ ⟨body⟩)Defines an anonymous procedure that takes any number of arguments and binds them to⟨args⟩.
lambda functions can capture their environment. That is to say, variables
bound outside the scope of the lambda are captured.
| Example: captured variables | |
|---|---|
let, let* and letrec syntax¶
let¶
The let keyword is used to define lexical bindings for local variables.
Variables defined this way are only visible for their body. Variables are bound to their expressions in order, but are not visible for each others binding expressions.
Let expressions return the last value returned in body.
let*¶
let* is similar to let, but each subsequent binding has access to the
previous:
The following code
is equivalent to:
letrec¶
letrec allows for the creation of recursive (or even mutually recursive) bindings:
| Example: letrec factorial | |
|---|---|
set! syntax¶
set! allows for the mutation of variables.
Values that are exported are considered to be immutable and attempting to set them is a syntax violation.
quote syntax¶
quote returns its argument literally without evaluation. It is often referred
to by it's alias, '.