3

Normally, for simple character strings, a leading backtick does the trick.

Example: `abc

However, if the string has some special characters, such as space, this will not work.

  • Example: `$"abc def"
  • Example: `$"BAT-3Kn.BK"

What are the rules when $"" is required?

kevinarpe
  • 20,319
  • 26
  • 127
  • 154

2 Answers2

4

Simple syntax for symbols can be used when the symbol consists of alphanumeric characters, dots (.), colons (:), and (non-leading) underscores (_). In addition, slashes (/) are allowed when there is a colon before it. Everything else requires the `$"" syntax.

Alexander Belopolsky
  • 2,228
  • 10
  • 26
2

The book 'Q for mortals', which is available online, has a section discussing datatypes. For symbols it states:

A symbol can include arbitrary text, including text that cannot be directly entered from the console – e.g., embedded blanks and special characters such as back-tick. You can manufacture a symbol from any text by casting the corresponding list of char to a symbol. (You will need to escape special characters into the string.) See §6.1.5 for more on casting.

q)`$"A symbol with blanks and `"
`A symbol with blanks and `

The essential takeaway here is that converting a string to a symbol is required when special characters are involved. In the examples you have given both space " " and hyphen "-" are characters that cannot be directly placed into a symbol type.

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36