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
( |
<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
|
*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 |
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
|
|
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) // 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 |
|||
---|---|---|---|---|
|
|
|
|
|
|
Forbidden |
Forbidden |
Forbidden |
Forbidden |
|
Required |
Allowed |
Allowed |
Allowed |
|
Required |
Required |
Allowed |
Allowed |
|
Required |
Allowed |
Automatic |
Allowed |
|
Required |
Required |
Automatic |
Allowed |
|
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 |
Permits |
Permits other keywords |
---|---|---|---|
|
— |
No |
No |
|
— |
If next method permits |
If next method permits |
|
— |
Yes |
If next method permits |
|
— |
Yes |
Yes |
|
— |
Yes |
Yes |
|
Extra arguments |
No |
No |
|
Keywords/values |
If next method permits |
If next method permits |
|
Keywords/values |
Yes |
If next method permits |
|
Keywords/values |
Yes |
Yes |
|
Keywords/values |
Yes |
Yes |