Syntax Cheat Sheet#

Literals#

Type

Dylan Syntax

Learn More…

Booleans

#t // true
#f // false

Numbers

42       // A decimal integer
#b101010 // A binary integer
#o52     // An octal integer
#x2A     // A hexadecimal integer
-42.5    // A floating point number
6.02E23  // A floating point number

Strings

'a'       // A character
"Hello"   // A simple string
"Hello\n" // An escape sequence

Symbols

#"hello"  // A symbol
#"HELLO"  // The same symbol
hello:    // Again, in keyword syntax

Collections

#(1 . "one") // A literal <pair>
#(1, 2, 3)   // A literal <list>
#[1, 2, 3]   // A literal <vector>

Naming Conventions#

These are conventions only; they have no semantic value to the compiler.

Classes

Class names begin / end with angle brackets (< and >).

<float>
<stretchy-vector>

Constants

Constants begin with $.

$word-size
$tag-bits

Module Variables

Module variable names begin / end with *.

This does not apply to local variables that have been declared with let.

*news*
*command-dispatcher*

Predicate Functions

Predicate functions return #t or #f. They end in ?.

even?
instance?

Getters & Setters

Getters read a value while setters write a value. Setter functions end in -setter. The compiler uses this convention to find the function to call for :=.

window.size := 3
size-setter(3, window)

Operators#

Class

Dylan Syntax

Learn More…

Equality & Comparison

 a < b    // a less than b?
 a > b    // a greater than b?
 a = b    // a equal to b?
 a ~= b   // a not equal b
 a == b   // a identical to b
 a ~== b  // a not identical to b
~a        // logical negation

Arithmetic

a + b        // add a and b
a * b        // mulitply a and b
a - b        // subtract b from a
a / b        // divide a by b
modulo(a, b) // modulus of a by b
negative(a)  // negative of a

Collections

c[k]       // elem. k of col. c
c[k] := x  // set elem. k of col. c
c.empty?   // is c empty?
c.size     // how big is c?

Sequence

add(c, x)    // add x to copy of c
remove(c, x) // rem x from copy of c
sort(c)      // copy of c, sorted
reverse(c)   // copy of c, reversed

Bitwise & Logical

a | b        // Boolean OR
a & b        // Boolean AND
logior(a, b) // Bitwise inclusive OR
logxor(a, b) // Bitwise exclusive OR
logand(a, b) // Bitwise AND
lognot(a, b) // Bitwise NOT
ash(a, b)    // Shift left: a << b
ash(a, -b)   // Shift right: a >> b

String Formatting#

Example: format(stream, "%s:%d", host, port)

Directive

Argument Type

Description

%d

<integer>

decimal number

%b

<integer>

binary number

%o

<integer>

octal number

%x

<integer>

hexadecimal number

%c

<character>

character, no quotes

%s

<object>

“pretty” format

%=

<object>

“unique” format

%%

None

literal %

Parameter Lists#

This table shows what is required/allowed in method parameter lists, depending on what is specified in the generic function’s parameter list.

Generic function’s parameter list

Methods’ parameter lists

#key

#key a, b

#all-keys

#rest

(x)

Forbidden

Forbidden

Forbidden

Forbidden

(x, #key)

Required

Allowed

Allowed

Allowed

(x, #key a, b)

Required

Required

Allowed

Allowed

(x, #key, #all-keys)

Required

Allowed

Automatic

Allowed

(x, #key a, b, #all-keys)

Required

Required

Automatic

Allowed

(x, #rest r)

Forbidden

Forbidden

Forbidden

Required

This table shows the different kinds of parameter lists that a method can have, what the r variable contains for each, and which keywords are permitted by each.

Method’s parameter list

Contents of r

Permits a: and b:

Permits other keywords

(x)

No

No

(x, #key)

If next method permits

If next method permits

(x, #key a, b)

Yes

If next method permits

(x, #key, #all-keys)

Yes

Yes

(x, #key a, b, #all-keys)

Yes

Yes

(x, #rest r)

Extra arguments

No

No

(x, #rest r, #key)

Keywords/values

If next method permits

If next method permits

(x, #rest r, #key a, b)

Keywords/values

Yes

If next method permits

(x, #rest r, #key, #all-keys)

Keywords/values

Yes

Yes

(x, #rest r, #key a, b, #all-keys)

Keywords/values

Yes

Yes