Previous section: Language Overview

Dylan reference manual -- Lexical Notation

2. Syntax

Lexical Notation

Here are the lexical conventions used in Dylan programs.
White space (including spaces, tabs, newlines, and newpage characters) serves as a delimiter. The amount of contiguous white space is not significant. Thus, any number of contiguous white space characters can be used for formatting.
Variable names are a series of alphanumeric characters, and characters from the set ! & * < = > | ^ $ % @ _ - + ~ ? /, that do not begin with one of the special characters - + ~ ? /. If a variable name begins with a numeric character, the name must contain two alphabetic characters in a row. Variable names are not case-sensitive.
Infix operators are the following one- or two-character sequences: + - * / - = == < > <= >= ~= ~ & | ^.
An infix operator variable name is the corresponding infix operator, prefixed with the infix operator escape character \. This allows an infix operator to be used wherever a variable name is allowed (for example, as the variable name in a define method or as a function argument).
The syntax of numbers is described in the numerics
section of this manual.
Literal strings are delimited by double-quote marks. The characters between the quotes are the elements of the string. Within the string, white space is significant (it contributes to the string). Double quotes can be included in strings by preceding them with a backslash character. Within a string, backslash (\) has the general effect of quoting the following character. To include a backslash in a string, the backslash must be preceded by another backslash.
Symbols are interned strings. They are preceded by a See the section on symbols and keywords for more details.
An alternative syntax for symbols is "keyword syntax." See the section on symbols and keywords for more details.
#(1, 2, 3)
Literal lists are delimited by open and close parentheses, and preceded by a sharp-sign. The items between the parentheses are the elements of the list. They are separated with commas.
#[1, 2, 3]
Literal vectors (one-dimensional arrays) are delimited with square brackets, and preceded by a sharp-sign. The items between the square brackets are the elements of the vector. They are separated with commas.
Character constants are represented by delimiting the character with single quotes.
A pair of slashes indicates the start of a comment. The comment continues until the end of the line. At the start of a new line, regular parsing begins again.
/* ... */
Slash-star pairs delimit extended comments. These comments can run over multiple lines. Extended comments can be nested.
The hash-sign t syntax is used to indicate the canonical true value.
The hash-sign f syntax is used to indicate the canonical false value.
#key, #rest, #next and #all-keys are used to indicate
special tokens in parameter lists.

Naming Conventions

Several conventions for naming variables help programmers identify the purposes of variables. The names of variables do not affect the semantics of a program, but are simply used to improve readability.

Dylan uses the following naming conventions:

Variables used to hold classes begin and end with angle brackets.

<window>	<object>	<character>
<number>	<stream>	<list>
Module variables that are designed to have their values change in the course of a program (i.e., variables that are not read-only) begin and end with asterisks.
Program constants (read-only module variables) begin with a dollar sign.
The names of most predicate functions end with a question mark. Predicates are functions which return a true or false value.[6]
subclass?	even?
The names of most operations that destructively modify data structures end with an exclamation point.[7] These names sometimes contrast with versions that allocate new memory for the result.
reverse!	(non-destructive version is reverse)
sort!	(non-destructive version is sort)
Operations that retrieve a value from a location are called getters. Operations that store into a location are called setters. In general, getters and setters come in pairs. Setter variable names are derived by appending

"-setter" to the corresponding getter variable name. Actually, this is not simply a convention. The rule is exploited to generate setter names from getter names automatically, and it is used to expand calls to :=.

Getter 	Setter 
window-position	window-position-setter
table-size	table-size-setter
window-color	window-color-setter
These two expressions are equivalent; they both set the color of

my-window to green:

window-color-setter (green, my-window)
my-window.window-color := green

Next section: Expressions