# casting number to symbol

**URL:** <https://forum.kx.com/t/casting-number-to-symbol/11394>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [November 29, 2016, 7:08am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394 "2016-11-29T07:08:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)\
**Post date:** [November 29, 2016, 7:08am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/1 "2016-11-29T07:08:00Z")

</div>

Again, looking for some **documentation** on why the following does not work:

`$($)1 / does work; shows `1

`$1 / type error why ?

---

<div class="post-metadata">

**Author:** ![AquaQMatt](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@AquaQMatt](https://forum.kx.com/u/AquaQMatt)\
**Post date:** [November 29, 2016, 7:37am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/2 "2016-11-29T07:37:00Z")

</div>

Hi,&nbsp;

When casting from an numerical type to type symbol, you should first cast the numeric to a string, then cast again to a symbol.

q)testnum:10

q)testnumstring:string testnum

q)testnumstring

“10”

q)`$testnumstring

`10

As to why this is the case in KDB+, I’m not actually too sure.&nbsp;

Regards,  
Matt

---

<div class="post-metadata">

**Author:** ![Nick10](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@Nick10](https://forum.kx.com/u/Nick10)\
**Post date:** [November 29, 2016, 7:39am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/3 "2016-11-29T07:39:00Z")

</div>

($) forces nomadic evaluation of $ which is ‘string’

so your first line is actually:

`$ string 1

`$ 1 does not work because $ requires a character vector as its right ooerand to cast into a symbol with ` as its left operand.

why are you placing parentheses around $?

---

<div class="post-metadata">

**Author:** ![Nick10](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@Nick10](https://forum.kx.com/u/Nick10)\
**Post date:** [November 29, 2016, 7:41am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/4 "2016-11-29T07:41:00Z")

</div>

thanks to autocorrect:

nomadic -\> monadic.

---

<div class="post-metadata">

**Author:** ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)\
**Post date:** [November 29, 2016, 7:53am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/5 "2016-11-29T07:53:00Z")

</div>

Nick,  
What you are saying is probably right (and I believed the same thing too). However, &nbsp;I am trying to iron out the **missing area in the documentation**. &nbsp;Where does the documentation say “$ requires a character vector as its right ooerand to cast into a symbol with ` as its left operand”

I dont see it on the wiki&nbsp;

http://code.kx.com/wiki/Reference/DollarSign

---

<div class="post-metadata">

**Author:** ![Nick10](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@Nick10](https://forum.kx.com/u/Nick10)\
**Post date:** [November 29, 2016, 8:20am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/6 "2016-11-29T08:20:00Z")

</div>

you are right, i don’t see it.

you can read about it here:

https://a.kx.com/q/d/a/q1.htm#Creating Varchars

---

<div class="post-metadata">

**Author:** ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)\
**Post date:** [November 29, 2016, 8:27am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/7 "2016-11-29T08:27:00Z")

</div>

One more question. Not really related to the current topic. Since you wrote a book and are pretty much q god level individual, is some (most) part of kdb just trying to infer behavior **because** doc is missing.

I am just trying to contrast it with lets say a C question where there a standard (although a standard can show behavior as **undefined** as well).

---

<div class="post-metadata">

**Author:** ![Nick10](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@Nick10](https://forum.kx.com/u/Nick10)\
**Post date:** [November 29, 2016, 9:07am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/8 "2016-11-29T09:07:00Z")

</div>

you are correct, there is no standard. though the wiki is slowly emerging as the definitive source for the language’s behavior.

operators are overloaded based on the type of their operands. the behavior can also change based on the value of the operand: positive, negative and null. that leaves a lot of flexibility for the language.

if calling an operator with a specific type currently throws a `type error and a logical alternative is found, the language is enhanced in subsequent releases. updating the wiki sometimes trails.

this can be both frustrating and also the beginning of an ‘unexpected journey’.

the wiki benefits from people like you that point out its deficiencies. thank you.

---

<div class="post-metadata">

**Author:** ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)\
**Post date:** [November 29, 2016, 9:16am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/9 "2016-11-29T09:16:00Z")

</div>

I have been asking rights to edit the wiki since I am a pretty " **by the book**" computer scientist.&nbsp;  
However, I do not want kx to take my word for it. My edits (like the posts in this forum) will be subject to review.

This will make life for the community better (I think).

Sigh.

---

<div class="post-metadata">

**Author:** ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)\
**Post date:** [November 29, 2016, 9:19am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/10 "2016-11-29T09:19:00Z")

</div>

I have been asking rights to edit the wiki since I am a pretty " **by the book**" computer scientist.&nbsp;  
However, I do not want kx to take my word for it. My edits (like the posts in this forum) will be subject to review.

This will make life for the community better (I think).

Sigh.

---

<div class="post-metadata">

**Author:** ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)\
**Post date:** [November 29, 2016, 9:19am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/11 "2016-11-29T09:19:00Z")

</div>

I have been asking rights to edit the wiki since I am a pretty " **by the book**" computer scientist.&nbsp;  
However, I do not want kx to take my word for it. My edits (like the posts in this forum) will be subject to review.

This will make life for the community better (I think).

Sigh.

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [November 29, 2016, 10:23am UTC](https://forum.kx.com/t/casting-number-to-symbol/11394/12 "2016-11-29T10:23:00Z")

</div>

note that `$x is shorthand for “S”$x (iirc, originally added to make k3 users feel more at home. A token gesture perhaps!).

This alone should mostly explain why the rhs should be a char or char vector. As many other ops, it penetrates lists, tables and dictionaries, e.g.

q)`$“hello”

`hello

q)`$(“hello”;“world”)

`hello`world

q)`$()

x &nbsp; &nbsp;

* * *

hello

world

q)`$`a`b!(“hello”;“world”)

a| hello

b| world

q)`$`a`b!2#enlist(“hello”;“world”)

a| hello world

b| hello world

We did reply to your requests earlier this year for edit rights to the wiki; please check your spam folder in case our responses landed there.

thanks,

Charlie
