How do I cast a string to a symbol?
By applying the $ (cast) operator while passing ` (the null symbol) as its left argument:
q)` $ “foo”
`foo
q)
The cast operator also accepts an uppercase type character as its left argument:
q)”S” $ “foo”
`foo
q)
Moreover, you can convert a list of strings at once:
q)”S” $ (“foo”; “bar”; “baz”)
`foo`bar`baz
q)
To go the other way, use the string function:
q)string `foo
“foo”
q)
Since the string function is implemented as the monadic form (i.e., single argument overload) of the k function $ —
q)string
$:
q)
— it is also possible to write the above cast as follows:
q)($)`foo
“foo”
q)
Although we don’t recommend it, we thought you should know in case you see it in the wild.
See also: type