3.3.2 Bindings: Mappings between objects and names
A binding is a mapping between an object and a name. The name can be a module variable, module constant, or local variable.
Here, we give the object 3.14159 the name $pi, where $pi is a module constant:
? define constant $pi = 3.14159;
Here, we give the object "apple" the name *my-favorite-pie*, where *my-favorite-pie* is a module variable:
? define variable *my-favorite-pie* = "apple";
More than one variable can contain a particular object, so, in effect, an object can have many names. Here, we define a new variable that contains the very same pie:
? define variable *your-favorite-pie* = *my-favorite-pie*; ? *your-favorite-pie* == *my-favorite-pie*; #t
When you define a method, define method creates a binding between a name and a method object:
? define method say-greeting (greeting :: <object>);
format-out("%s\n", greeting);
end;
All the bindings that we have created in this section so far are accessible within a module. (For information about modules, see Chapter 13, Libraries and Modules.) Figure 3.3 shows how you can picture each binding as a link between a name and another object.
Local variables are also bindings, but they are accessible only within a certain body of code; for example,
? begin
let radius = 5.0;
let circumference = 2.0 * $pi * radius;
circumference;
end;
Bindings can be constant or variable. You can use the assignment operator to change a variable binding, but you cannot change a constant binding. Module constants are constant bindings; module variables and local variables are variable bindings.
|





