2.3 Variables and constants
We can define variables for storing values:
? define variable *my-number* = 7; ? define variable *your-number* = 12;
In Dylan, these variables are called module variables. A module variable has a name and a value. For now, you can consider module variables to be like global variables in other languages. (See Section 13.2, page 189, for information about modules.) Module variables can have different values assigned to them during the execution of a program. When you define a module variable, you must initialize it; that is, you must provide an initial value for it. For example, the initial value of *my-number* is 7.
Convention: Module variables have names that start and end with an asterisk — for example, |
We can ask the listener for the values of module variables:
? *my-number*; 7 ? *your-number*; 12
We can add the values stored in these variables:
? *my-number* + *your-number*; 19
We can multiply the values stored in these variables:
? *my-number* * *your-number*; 84
We can use the assignment operator, :=, to change the values stored in a variable:
? *my-number* := 100; 100




