#

The # filter has one argument, a set filter or a string filter . The # filter always matches a position when its argument does.

Set filter as argument

If its argument is a set filter, then the value of the #-filter is the number of squares in its argument. The number of squares of a set is also called the cardinality of that set. The number of squares in the empty set is 0. Suppose for example that the current position is the start position of a chess game. Then

  #K  1
  #[Kk]  2
  #P attackedby K  3

To find a position where there are multiple white queens, you could use:

  #Q>1

In this case, however, you could just use

  Q>1

because a set filter that is compared to a number is automatically converted to its cardinality (that is, the set filter is prefaced by #).

String filter as argument

(New in CQL 6.1) If its argument is a string filter, then the value of the #-filter is the number of characters in the string denoted by that argument.

  #"Capablanca"  10
  #""  0

Dictionary as argument

If D is a dictionary, then #D number of entries in D (see here for more information).
  dictionary Dict
  #Dict==0
  Dict["pin"]="knight"
  #Dict==1

Examples

The # filter is used in chameleon.cql, and queenpawnpinecho.cql.

In chameleon.cql, the line

  #==source:# 
checks that the number of pieces in the current positions is the same as the number of pieces in the position named by the variable source, using the : filter.