Skip to content

? Enum Extend

Extend an enumeration

Syntax: x?y, ?[x;y]


  • y is a list
  • x is a handle to a:


fills in any missing items in x, returns y as an enumeration of the variable named in x with filling in missing items in it. (Unlike Enumerate.)


Note that ? preserves the attribute/s of the right-argument but $ does not.



fills in any missing items in file x, loads it into the session as a variable of the same name, and returns y as an enumeration of it.

q)bar:`c`d  /about to be overwritten
q)\ls -l bar
"-rw-r--r--  1 sjt  staff  16  3 Mar 12:53 bar"

In detail:

`:enumname ?`a`b`c

executes the following steps:

  1. opens the file enumname and locks it (see note)
  2. reads contents of the file enumname, interning each symbol, and binds the resulting symbol vector to enumname
  3. enumerates according to `enumname ?`a`b`c
  4. appends any new symbols to the file `:enumname
  5. closes file enumname, which automatically unlocks it

Locking the file

The file is locked at a process level for writing during .Q.en only. Avoid reading from any file which may be being written to.

The system call used is

One can verify that the file system supports the write lock by stracing the following q script locktest.q on the filesystem which you are sharing between those machines:

$ strace q locktest.q 2>&1 | grep F_SETLKW
fcntl(1024, F_SETLKW, {type=F_WRLCK, whence=SEEK_CUR, start=0, len=0}) = 0

If that return value is not 0, then the lock failed and may not be supported by the chosen filesystem. Kdb+ does not report an error if that lock call fails.

Enum Extend is a uniform function.

Enumerate, Enumeration, .Q.en (enumerate varchar cols), ? query overloads
Enumerations, File system
Enumerating varchar columns in a table
Q for Mortals §7.5 Enumerations