Types of directions

There are eight basic directions:

basic direction
These refer to the natural directions on the chessboard from the white perspective: e.g., up is in the direction of increasing rank.

There are also five compound directions, which represent two or more basic directions:

compound directionbasic directions represented
diagonalnortheast, northwest, southeast, southwest
orthogonalup, down, left, right
verticalup, down
horizontalleft, right
anydirectionup, down, left, right, northeast

A direction keyword is the name of a direction, like northeast.

direction filters

Each basic direction keyword is associated with a corresponding direction filter. A direction filter consists of the a direction keyword followed by an optional range followed by a set filter.
direction_filter := direction_keyword set_filter
direction_filter :=  direction_keyword range set_filter

If the range is missing it is taken to be 1 7.

A direction filter represents the set of squares represented by shifting its argument, in the direction indicated by its direction keyword, a number of times indicated by its range. For example:

up 1 d4  d5
up 2 d4  d6
up 3 d4  d7
up 1 3 d4  d5-7
up d4  d5-8
down 1 d4  d3
down d4  d1-3
left 1 [d4,e5] [c4,d5]
left [d4,e5]  [a-c4,a-d5]
right a1-8  b-h1-8
right 1 a-h2  b-h2
right 6 7 a-h2  [g2,h2]
The range in the direction filter can include negative numbers. These denote a direction opposite to the direction of the direction keyword in the direction filter.
up -2 d4  d2
right -1 1 d4  c-e4
Each compound direction keyword is likewise associated with a direction filter. These represents the union of the sets corresponding to the basic directions in the compound direction filter. For example:
vertical 3 d4 
 {up 3 d4} or {down 3 d4}

diagonal 1 d4  [e5,c5,c3,e3]

orthogonal d4  [a-c4,d5-8,e-h4,d1-3]
Although a compound direction filter can have range with negative bounds, it is always unnecessary to include this, since each compound direction filter includes the opposite direction of each of its basic direction elements:
horizontal 0 1 d4  c-e4
horizontal -1 0 d4  c-e4
horizontal -1 1 d4  c-e4
Note that these examples can be used for any sets, not just squares. For example, suppose the current position is the start position. Then:

up 1 P  a-h3

up N  [b2-8,g2-8]

right 1 [Rq]  [b1,b8]

right 1 attack (Q A)
  right 1 [c-e2,e1,c1] 
These can be combined with other primitives, including direction filters. For example, to find squares a knight's hop away from a Q, use:
flip up 2 right 1 Q
If the current position were the starting position, for example, this expression would be represent [f2,e3,c3,b2] Similarly,
  diagonal diagonal h1
is the set of light squares:
  diagonal diagonal h1
   diagonal diagonal 1 7 h1
   diagonal [g2,f3,e4,d5,c6,b7,a8]
   diagonal 1 7 [g2,f3,e4,d5,c6,b7,a8]
This last expression is the set of light squares, because every light square can be reached by moving a distance from 1 to 7 along a diagonal direction from one of these squares. For instance:
  h1  southwest 1 g2
  g8  northeast 3 d5

directions in ray

Directions are also used as a parameter to the ray filter. See the ray filter documentation for more information on that usage.